Skip to content

Commit b26489e

Browse files
authored
Merge pull request #77 from ravigurram8/topic-release-3
EC2-docker-linux cft
2 parents b1d3766 + 20489b3 commit b26489e

2 files changed

Lines changed: 150 additions & 2 deletions

File tree

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ It provides a pre-built catalog of products which are ready to use out of the bo
3535
3. 3 Private Subnets
3636
4. IGW
3737
5. NAT Instance / NAT Gateway
38-
6. Bastion Hosts
38+
6. Bastion Hosts (optional)
3939
7. Application Load Balancer
4040
8. Listener
4141
9. ACM or External Certificates for SSL
@@ -55,6 +55,10 @@ Deploying an Application Load Balancer as part of Research Gateway deployment he
5555
1. Isolates your portal from being directly exposed over the internet. The ALB allows only https(s) traffic through.
5656
2. Helps to serve the application on a secure port using SSL certificates stored in AWS ACM.
5757

58+
create an ALB security Group with the following inbound and outbound rules
59+
Inbound Rules - HTTP 80 ,HTTPS-443,SSH-20 .
60+
outbound Rules - All Traffic.
61+
5862
Use the AWS CLI to create an Application Load Balancer choosing all three public subnets created by the quickstart above.
5963

6064
aws elbv2 create-load-balancer --name research-gw-alb --subnets subnet-abcd1234 subnet-abcd5678 subnet-abcd9876 --security-groups sg-abcd1234 --region us-east-1
@@ -115,6 +119,8 @@ As a part of this deployment, you will create an AMI for the portal EC2 instance
115119
- AWS ImageBuilder
116120
- AWS EC2
117121
- AWS IAM
122+
- AWS service catalog
123+
- Elastic container Registery
118124

119125
## Installing the required 3rd party software
120126

@@ -142,6 +148,7 @@ You can create the AMI with pre-requisites yourself by following these steps:
142148
export AWS_DEFAULT_REGION="Your_Region"
143149

144150
- Clone this repo on a machine.
151+
- Target Account number must be added in Admin Account-ECR and give permission to access image builds
145152
- Create a Role and attach a policy which permits ECR and EC2 actions and Replace the "iam-instance_profile" :"<your_rolename>" in builders section which is in the packer-rg.json.
146153
- Run packer build packer-rg.json
147154

@@ -152,7 +159,15 @@ You can create the AMI with pre-requisites yourself by following these steps:
152159
### Installing Research Gateway
153160

154161
Clone this repo on a machine that has AWS CLI configured with Default output format as JSON.
155-
Run deploy.sh with the following parameters
162+
Run deploy.sh with the following parameters.
163+
164+
- Check aws configure before running script
165+
aws configure
166+
AWS Access Key ID: <access Key ID>
167+
AWS Secret Access Key :<secret Key>
168+
Default region name: <region-name>
169+
Default output format : json
170+
156171

157172
| Parameter# | Purpose |
158173
| ---------- | ------------------------------------------------------------------------------------------ |

cft-templates/ec2-linux-docker.yml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
Metadata:
2+
License: Apache-2.0
3+
AWSTemplateFormatVersion: '2010-09-09'
4+
Description: 'AWS CloudFormation Template to create an EC2 instance
5+
**WARNING** This template creates an Amazon EC2 instance and an Elastic IP Address.
6+
You will be billed for the AWS resources used if you create a stack from this template.'
7+
8+
Parameters:
9+
Namespace:
10+
Type: String
11+
Description: An environment name that will be prefixed to resource names
12+
S3Mounts:
13+
Type: String
14+
Description: A JSON array of objects with name, bucket, and prefix properties used to mount data
15+
IamPolicyDocument:
16+
Type: String
17+
Description: The IAM policy to be associated with the launched workstation
18+
EnvironmentInstanceFiles:
19+
Type: String
20+
Description: >-
21+
An S3 URI (starting with "s3://") that specifies the location of files to be copied to
22+
the environment instance, including any bootstrap scripts
23+
InstanceType:
24+
Description: Choose the instance type for this instance. e.g. t2.small
25+
Type: String
26+
Default: t2.small
27+
AllowedValues: [t2.nano, t2.micro, t2.small, t2.medium]
28+
ConstraintDescription: must be a valid EC2 instance type.
29+
KeyPair:
30+
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance. If no key pairs exist, please create one from the button next to the dropdown. Please contact your Administrator if you are unable to create one.
31+
Type: AWS::EC2::KeyPair::KeyName
32+
ConstraintDescription: must be the name of an existing EC2 KeyPair.
33+
AllowedSSHLocation:
34+
Description: The IP address range that can be used to SSH to the EC2 instances
35+
Type: String
36+
MinLength: '9'
37+
MaxLength: '18'
38+
Default: 0.0.0.0/0
39+
AllowedPattern: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})
40+
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
41+
LatestAmiId:
42+
Type: 'AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
43+
Default: '/aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id'
44+
45+
Conditions:
46+
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
47+
48+
Resources:
49+
IAMRole:
50+
Type: 'AWS::IAM::Role'
51+
Properties:
52+
RoleName: !Join ['-', [Ref: Namespace, 'ec2-role']]
53+
Path: '/'
54+
AssumeRolePolicyDocument:
55+
Version: '2012-10-17'
56+
Statement:
57+
- Effect: 'Allow'
58+
Principal:
59+
Service:
60+
- 'ec2.amazonaws.com'
61+
Action:
62+
- 'sts:AssumeRole'
63+
Policies:
64+
- !If
65+
- IamPolicyEmpty
66+
- !Ref 'AWS::NoValue'
67+
- PolicyName: !Join ['-', [Ref: Namespace, 's3-studydata-policy']]
68+
PolicyDocument: !Ref IamPolicyDocument
69+
70+
InstanceProfile:
71+
Type: 'AWS::IAM::InstanceProfile'
72+
Properties:
73+
InstanceProfileName: !Join ['-', [Ref: Namespace, 'ec2-profile']]
74+
Path: '/'
75+
Roles:
76+
- Ref: IAMRole
77+
78+
EC2Instance:
79+
Type: AWS::EC2::Instance
80+
CreationPolicy:
81+
ResourceSignal:
82+
Timeout: PT3M
83+
Properties:
84+
UserData:
85+
Fn::Base64: !Sub |
86+
#!/usr/bin/env bash
87+
sudo yum install zip -y
88+
sudo yum install unzip -y
89+
# Install AWS CLI version2
90+
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
91+
unzip awscliv2.zip
92+
sudo ./aws/install
93+
# Install Mysql Shell
94+
sudo yum install mysql -y
95+
# Install cfn
96+
yum install -y aws-cfn-bootstrap
97+
# Download and execute shell script
98+
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap_mysql.sh" "/tmp"
99+
chmod 500 "/tmp/get_bootstrap_mysql.sh"
100+
/tmp/get_bootstrap_mysql.sh "${EnvironmentInstanceFiles}" '${S3Mounts}'
101+
# Signal result to CloudFormation
102+
/opt/aws/bin/cfn-signal --exit-code 0 --resource EC2Instance --region ${AWS::Region} --stack ${AWS::StackName}
103+
InstanceType: !Ref 'InstanceType'
104+
SecurityGroups: [!Ref 'InstanceSecurityGroup']
105+
KeyName: !Ref 'KeyPair'
106+
ImageId: !Ref 'LatestAmiId'
107+
IamInstanceProfile: !Ref InstanceProfile
108+
Tags:
109+
- Key: Name
110+
Value: !Join ['-', [Ref: Namespace, 'ec2-linux']]
111+
- Key: Description
112+
Value: EC2 workspace instance
113+
114+
InstanceSecurityGroup:
115+
Type: AWS::EC2::SecurityGroup
116+
Properties:
117+
GroupDescription: Enable SSH access
118+
SecurityGroupIngress:
119+
- IpProtocol: tcp
120+
FromPort: '22'
121+
ToPort: '22'
122+
CidrIp: !Ref 'AllowedSSHLocation'
123+
124+
Outputs:
125+
InstanceId:
126+
Description: InstanceId of the newly created EC2 instance
127+
Value: !Ref 'EC2Instance'
128+
InstanceIPAddress:
129+
Description: IP address of the newly created EC2 instance
130+
Value: !GetAtt [EC2Instance, PublicIp]
131+
InstanceDNSName:
132+
Description: DNS name of the newly created EC2 instance
133+
Value: !GetAtt [EC2Instance, PublicDnsName]

0 commit comments

Comments
 (0)