Skip to content

Commit 5f71b66

Browse files
authored
Merge pull request #215 from RLOpenCatalyst/main
Merge updates from main to topic-release
2 parents cd943b8 + af56d84 commit 5f71b66

15 files changed

Lines changed: 1348 additions & 1125 deletions

File tree

cft-templates/Rstudio.yml

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ Parameters:
2020
EBSVolumeSize:
2121
Description: The initial size of the volume (in GBs) EBS will use for storage.
2222
Type: Number
23-
Default: 8
23+
Default: 8
2424
InstanceType:
2525
Type: String
2626
Description: Choose the instance type e.g t3.medium (2vCPU , 2GiB RAM), t3.large (2vCPU, 8GiB RAM), t3.xlarge(4vCPU, 16GiB RAM)
2727
AllowedValues:
2828
- t3.medium
29-
- t3.large
30-
- t3.xlarge
29+
- t3.large
30+
- t3.xlarge
3131
ConstraintDescription: Valid instance type in the t3 families
3232
Default: t3.medium
3333
InitialUser:
@@ -39,8 +39,8 @@ Parameters:
3939
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.
4040
AvailabilityZone:
4141
Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created.
42-
Type: AWS::EC2::AvailabilityZone::Name
43-
42+
Type: AWS::EC2::AvailabilityZone::Name
43+
4444
Conditions:
4545
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
4646

@@ -59,6 +59,8 @@ Resources:
5959
- 'ec2.amazonaws.com'
6060
Action:
6161
- 'sts:AssumeRole'
62+
ManagedPolicyArns:
63+
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
6264
Policies:
6365
- !If
6466
- IamPolicyEmpty
@@ -73,7 +75,7 @@ Resources:
7375
Action:
7476
- 'ssm:GetParameter'
7577
- 'ssm:PutParameter'
76-
Resource: !Sub 'arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/*'
78+
Resource: !Sub 'arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/*'
7779

7880
InstanceProfile:
7981
Type: 'AWS::IAM::InstanceProfile'
@@ -109,14 +111,14 @@ Resources:
109111
- config1
110112
- config2
111113
config1:
112-
files:
114+
files:
113115
'/root/mount_study.sh':
114116
mode: '000755'
115117
owner: 'root'
116118
group: 'root'
117119
content: !Sub |
118120
#!/bin/sh
119-
su - ${InitialUser} -c "env PATH=$PATH:/usr/local/bin mount_s3.sh" 2>&1 >> /root/mount_s3.log
121+
su - ${InitialUser} -c "env PATH=$PATH:/usr/local/bin mount_s3.sh" 2>&1 >> /root/mount_s3.log
120122
'/root/set_user_token.sh':
121123
mode: '000755'
122124
owner: 'root'
@@ -125,11 +127,11 @@ Resources:
125127
#!/usr/bin/env bash
126128
# Get the session token
127129
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
128-
130+
129131
# Get the region to build the parameter name
130132
instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
131-
echo "Retrieved region ${region} from metadata service"
132-
133+
echo "Retrieved region ${instance_region} from metadata service"
134+
133135
# Get the instance id to build the parameter name
134136
instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id)
135137
@@ -138,11 +140,11 @@ Resources:
138140
password=$(echo -n "$instance_id$secret" | sha256sum | awk '{print $1}')
139141
echo "${InitialUser}:$password" | /usr/sbin/chpasswd
140142
echo "Set rstudio-user password"
141-
143+
142144
sleep 10
143145
public_key=$(curl http://localhost:8787/auth-public-key)
144146
145-
aws ssm put-parameter --name "/RL/RG/rstudio/public-key/$instance_id" --value '{"secret":"'$secret'","public_key":"'$public_key'"}' --region $instance_region --type SecureString --overwrite
147+
aws ssm put-parameter --name "/RL/RG/rstudio/public-key/$instance_id" --value '{"secret":"'$secret'","public_key":"'$public_key'"}' --region $instance_region --type SecureString --overwrite
146148
echo "Stored rstudio public key in SSM"
147149
'/var/log/rstudio.log':
148150
content: "\n"
@@ -154,7 +156,7 @@ Resources:
154156
commands:
155157
01_mount_study:
156158
cwd: '/root'
157-
command: '/root/mount_study.sh'
159+
command: '/root/mount_study.sh'
158160
02_set_user_token:
159161
cwd: '/root'
160162
command: '/root/set_user_token.sh'
@@ -179,23 +181,23 @@ Resources:
179181
Value: EC2 linux based Rstudio server
180182
- Key: cost_resource
181183
Value: !Sub ${AWS::StackName}
182-
UserData:
184+
UserData:
183185
Fn::Base64: !Sub |
184-
#!/bin/bash
186+
#!/bin/bash
185187
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1
186188
trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource RstudioEC2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR
187189
sudo yum update -y --security
188-
190+
189191
#add user(s)
190192
sudo useradd -m -s /bin/bash ${InitialUser}
191193
#Add user to the sudo group
192-
sudo usermod -a -G wheel ${InitialUser}
193-
194+
sudo usermod -a -G wheel ${InitialUser}
195+
194196
#Download and execute bootstrap script
195197
aws s3 cp "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
196198
chmod 500 "/tmp/get_bootstrap.sh"
197199
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${InitialUser}"
198-
200+
199201
# Add command to start on reboot
200202
crontab -l 2>/dev/null > "/tmp/crontab"
201203
echo '@reboot su - ${InitialUser} -c "env PATH=$PATH:/usr/local/bin mount_s3.sh" 2>&1 >> /root/mount_s3.log' >> "/tmp/crontab"
@@ -211,12 +213,12 @@ Outputs:
211213
InstanceDNSName:
212214
Value: !GetAtt RstudioEC2Instance.PublicDnsName
213215
Description: Public DNS Name
214-
InstanceIPAddress:
216+
InstanceIPAddress:
215217
Value: !GetAtt RstudioEC2Instance.PublicIp
216218
InstanceId:
217219
Value: !Ref 'RstudioEC2Instance'
218220
ApplicationPort:
219221
Value: '443'
220-
AvailabilityZone:
222+
AvailabilityZone:
221223
Description: AvailabilityZone of newly created Rstudio EC2Instance
222-
Value: !Ref AvailabilityZone
224+
Value: !Ref AvailabilityZone

cft-templates/ec2-EIP.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Parameters:
2929
EBSVolumeSize:
3030
Description: The initial size of the volume (in GBs) EBS will use for storage.
3131
Type: Number
32-
Default: 8
32+
Default: 8
3333
KeyPair:
3434
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.
3535
Type: AWS::EC2::KeyPair::KeyName
@@ -47,12 +47,12 @@ Parameters:
4747
Default: '/aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
4848
AvailabilityZone:
4949
Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created.
50-
Type: AWS::EC2::AvailabilityZone::Name
50+
Type: AWS::EC2::AvailabilityZone::Name
5151

5252
Conditions:
5353
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
5454

55-
Resources:
55+
Resources:
5656
IAMRole:
5757
Type: 'AWS::IAM::Role'
5858
Properties:
@@ -67,6 +67,8 @@ Resources:
6767
- 'ec2.amazonaws.com'
6868
Action:
6969
- 'sts:AssumeRole'
70+
ManagedPolicyArns:
71+
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
7072
Policies:
7173
- !If
7274
- IamPolicyEmpty
@@ -115,7 +117,7 @@ Resources:
115117
Value: EC2 workspace instance
116118
- Key: cost_resource
117119
Value: !Sub ${AWS::StackName}
118-
120+
119121
InstanceSecurityGroup:
120122
Type: AWS::EC2::SecurityGroup
121123
Properties:
@@ -138,4 +140,4 @@ Outputs:
138140
Value: !GetAtt [EC2Instance, PublicDnsName]
139141
AvailabilityZone:
140142
Description: AvailabilityZone of newly created EC2 instance
141-
Value: !Ref AvailabilityZone
143+
Value: !Ref AvailabilityZone

cft-templates/ec2-dcv.yml

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Metadata:
1+
Metadata:
22
License: Apache-2.0
33
AWSTemplateFormatVersion: '2010-09-09'
44
Description: 'AWS CloudFormation Template to create an GPU based EC2 instance with NICE DCV pre installed.'
@@ -27,14 +27,13 @@ Parameters:
2727
[
2828
t3.medium,
2929
t3.large,
30-
t3.xlarge,
31-
30+
t3.xlarge
3231
]
3332
ConstraintDescription: must be a valid EC2 instance type.
3433
EBSVolumeSize:
3534
Description: The initial size of the volume (in GBs) EBS will use for storage.
3635
Type: Number
37-
Default: 32
36+
Default: 32
3837
KeyPair:
3938
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.
4039
Type: AWS::EC2::KeyPair::KeyName
@@ -49,12 +48,12 @@ Parameters:
4948
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
5049
AvailabilityZone:
5150
Description: Select the availability zone in which to create the instance. If you plan to attach a secondary volume to the instance, create this instance in the same AvailabilityZone as the volume you created.
52-
Type: AWS::EC2::AvailabilityZone::Name
51+
Type: AWS::EC2::AvailabilityZone::Name
5352

5453
Conditions:
5554
IamPolicyEmpty: !Equals [!Ref IamPolicyDocument, '{}']
5655

57-
Resources:
56+
Resources:
5857
SSMPolicy:
5958
Type: AWS::IAM::ManagedPolicy
6059
Properties:
@@ -90,6 +89,7 @@ Resources:
9089
PolicyDocument: !Ref IamPolicyDocument
9190
ManagedPolicyArns:
9291
- Ref: SSMPolicy
92+
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
9393

9494
InstanceProfile:
9595
Type: 'AWS::IAM::InstanceProfile'
@@ -133,7 +133,7 @@ Resources:
133133
content: |
134134
[Desktop Entry]
135135
Type=Application
136-
Exec="/home/ec2-user/jupyter.sh"
136+
Exec="/home/ec2-user/Jupyter.sh"
137137
Hidden=false
138138
NoDisplay=false
139139
X-GNOME-Autostart-enabled=true
@@ -153,9 +153,9 @@ Resources:
153153
X-GNOME-Autostart-enabled=true
154154
Terminal=true
155155
Name=rstudio-server
156-
Comment=Icon for rstudio
157-
158-
156+
Comment=Icon for rstudio
157+
158+
159159
"/home/ec2-user/rstudio.sh":
160160
mode: "000755"
161161
owner: "ec2-user"
@@ -174,19 +174,19 @@ Resources:
174174
URL=$url
175175
Icon=$custom_icon
176176
EOL
177-
chmod +x "$desktop_file"
177+
chmod +x "$desktop_file"
178178
"/home/ec2-user/Jupyter.sh":
179179
mode: "000755"
180180
owner: "ec2-user"
181181
group: "ec2-user"
182182
content: !Sub |
183183
#!/bin/bash
184-
184+
185185
sleep 2
186186
jtoken=$(docker exec jupyterlab /bin/bash -c "jupyter server list" 2>&1 | grep token | awk '{print $2}' | sed 's/.*=//')
187187
188188
if [ -n "$jtoken" ]; then
189-
189+
190190
echo "Token value: $jtoken"
191191
else
192192
echo "Error: Unable to retrieve the Jupyter token."
@@ -203,7 +203,7 @@ Resources:
203203
URL=$url
204204
Icon=$custom_icon
205205
EOL
206-
chmod +x "$desktop_file"
206+
chmod +x "$desktop_file"
207207
"/home/ec2-user/mount_study.sh":
208208
mode: "000755"
209209
owner: "ec2-user"
@@ -220,15 +220,15 @@ Resources:
220220
group: "ec2-user"
221221
content: !Sub |
222222
#!/bin/bash
223-
# trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource EC2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR
223+
trap '/opt/aws/bin/cfn-signal --exit-code 1 --resource EC2Instance --region ${AWS::Region} --stack ${AWS::StackName}' ERR
224224
225225
# Get the session token
226226
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
227-
227+
228228
# Get the region to build the parameter name
229-
region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
230-
echo "Retrieved region ${region} from metadata service"
231-
229+
instance_region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/placement/region)
230+
echo "Retrieved region ${instance_region} from metadata service"
231+
232232
# Get the instance id to build the parameter name
233233
instance_id=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/instance-id)
234234
echo "Retrieved instance_id $instance_id from metadata service"
@@ -304,7 +304,7 @@ Resources:
304304
02_set_user_token:
305305
cwd: "/home/ec2-user"
306306
command: "/home/ec2-user/set_user_token.sh"
307-
307+
308308
Properties:
309309
UserData:
310310
Fn::Base64: !Sub |
@@ -314,14 +314,14 @@ Resources:
314314
# Download and execute bootstrap script
315315
aws s3 cp --region "${AWS::Region}" "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
316316
chmod 500 "/tmp/get_bootstrap.sh"
317-
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${AWS::Region}"
317+
/tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${AWS::Region}"
318318

319319
# Install supervisor and start on boot
320320
pip3 install supervisor crudini
321321

322322
# Route auth request to external authenticator and restart dcv
323323
/usr/local/bin/crudini --set /etc/dcv/dcv.conf security auth-token-verifier \"http://127.0.0.1:8445\"
324-
#/usr/local/bin/crudini --set /etc/dcv/dcv.conf clipboard primary-selection-copy false
324+
#/usr/local/bin/crudini --set /etc/dcv/dcv.conf clipboard primary-selection-copy false
325325
systemctl restart dcvserver
326326

327327
# Create dcv session start script
@@ -361,7 +361,7 @@ Resources:
361361
# # Download and execute bootstrap script
362362
# aws s3 cp --region "${AWS::Region}" "${EnvironmentInstanceFiles}/get_bootstrap.sh" "/tmp"
363363
# chmod 500 "/tmp/get_bootstrap.sh"
364-
# /tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${AWS::Region}"
364+
# /tmp/get_bootstrap.sh "${EnvironmentInstanceFiles}" '${S3Mounts}' "${AWS::Region}"
365365

366366
sleep 5
367367
docker run -d --restart always -e PASSWORD=Pass@123 -v /home/ec2-user:/home/ec2-user -p 8787:8787 relevancelab/rstudio_4.2.1:1.0.3
@@ -405,8 +405,8 @@ Resources:
405405
Ebs:
406406
VolumeSize: !Ref EBSVolumeSize
407407
Encrypted: true
408-
409-
408+
409+
410410

411411
PropagateTagsToVolumeOnCreation: true
412412
Tags:
@@ -416,7 +416,7 @@ Resources:
416416
Value: EC2 workspace instance
417417
- Key: cost_resource
418418
Value: !Sub ${AWS::StackName}
419-
419+
420420
InstanceSecurityGroup:
421421
Type: AWS::EC2::SecurityGroup
422422
Properties:
@@ -444,6 +444,6 @@ Outputs:
444444
ApplicationPort:
445445
Description: The Port in which the application is running
446446
Value: '8443'
447-
AvailabilityZone:
447+
AvailabilityZone:
448448
Description: AvailabilityZone of newly created EC2 instance
449-
Value: !Ref AvailabilityZone
449+
Value: !Ref AvailabilityZone

0 commit comments

Comments
 (0)