Skip to content

Commit f7190c2

Browse files
committed
Refined the template
1 parent 9aac1d1 commit f7190c2

File tree

4 files changed

+59
-65
lines changed

4 files changed

+59
-65
lines changed

CHANGELOG.MD

-13
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22
# Change Log
33
All notable changes to this project will be documented in this file.
44

5-
## [1.2.0] - 2022-09-30
6-
7-
### Changed
8-
- #2: better exception handling
9-
- #4: better cfn response
10-
- bump python runtime to 3.9
11-
- remove software not needed by default
12-
## [1.1.0] - 2020-11-11
13-
14-
### Changed
15-
- bump terraform version to 0.13.5
16-
- add parameter and bootstrap code to resize the cloud9 system volume.
17-
185
## [1.0.0] - inital release
196

207
### inital version

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
## Cloud 9 Bootstrapping
22

33
### Summary
4-
This example Cloudformation Deployment shows how to deploy an AWS Cloud9 Environment for yourself or team members and run an automated bootstrap so you can install software components needed on the fly.
4+
This Cloudformation Deployment shows how to deploy an AWS Cloud9 Environment for yourself or team members and run an automated bootstrap so you can install software components needed on the fly.
55
This is usefull for workshops, unified deployments, etc.
66

77
you may use the template directly or leverage the bash shell script for deployment
@@ -11,10 +11,10 @@ There are a few parameters you might want to adjust.
1111

1212
| Parameter Name | Description |
1313
| ------------- | ------------- |
14-
| ExampleC9InstanceType | Example Cloud9 EC2 instance type |
15-
| ExampleC9EnvType | Environment Type. For yourself or to be deployed to a team member 3rd person by you? |
16-
| ExampleOwnerArn | if you selected "3rd person" when choosing ExampleC9EnvType please add the OwnerARN of the User or Role |
17-
| ExampleC9InstanceVolumeSize | The size of the System Volume for the Cloud9 instance |
14+
| C9InstanceType | Cloud9 EC2 instance type |
15+
| C9EnvType | Environment Type. For yourself or to be deployed to a team member 3rd person by you? |
16+
| OwnerArn | if you selected "3rd person" when choosing C9EnvType please add the OwnerARN of the User or Role |
17+
| C9InstanceVolumeSize | The size of the System Volume for the Cloud9 instance |
1818

1919
### Some tech Details
2020
This deployment uses Cloudformation to deploy Cloud9

example_instancestack.yaml cloud9_instancestack.yaml

+52-44
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ AWSTemplateFormatVersion: '2010-09-09'
33
Description: AWS CloudFormation template for dynamic Cloud 9 setups. Creates a Cloud9
44
bootstraps the instance.
55
Parameters:
6-
ExampleC9InstanceType:
7-
Description: Example Cloud9 instance type
6+
C9InstanceType:
7+
Description: Cloud9 instance type
88
Type: String
99
Default: t3.small
1010
AllowedValues:
@@ -13,34 +13,41 @@ Parameters:
1313
- t3.small
1414
- t3.medium
1515
ConstraintDescription: Must be a valid Cloud9 instance type
16-
ExampleC9EnvType:
16+
C9EnvType:
1717
Description: Environment type.
1818
Default: self
1919
Type: String
2020
AllowedValues:
2121
- self
2222
- 3rdParty
2323
ConstraintDescription: must specify self or 3rdParty.
24-
ExampleOwnerArn:
24+
OwnerArn:
2525
Type: String
2626
Description: The Arn of the Cloud9 Owner to be set if 3rdParty deployment.
2727
Default: ""
28-
ExampleC9InstanceVolumeSize:
28+
C9InstanceVolumeSize:
2929
Type: Number
3030
Description: The Size in GB of the Cloud9 Instance Volume.
3131
Default: 15
32-
32+
Project:
33+
Type: String
34+
Description: Project Name.
35+
Default: ""
36+
ShutdownTimeout:
37+
Type: Number
38+
Description: Inactivity time before shutting down the instance in seconds
39+
Default: 3600
3340
Conditions:
34-
Create3rdPartyResources: !Equals [ !Ref ExampleC9EnvType, 3rdParty ]
41+
Create3rdPartyResources: !Equals [ !Ref C9EnvType, 3rdParty ]
3542

3643
Resources:
3744
################## PERMISSIONS AND ROLES #################
38-
ExampleC9Role:
45+
C9Role:
3946
Type: AWS::IAM::Role
4047
Properties:
4148
Tags:
4249
- Key: Environment
43-
Value: AWS Example
50+
Value: AWS
4451
AssumeRolePolicyDocument:
4552
Version: '2012-10-17'
4653
Statement:
@@ -55,7 +62,7 @@ Resources:
5562
- arn:aws:iam::aws:policy/AdministratorAccess
5663
Path: "/"
5764

58-
ExampleC9LambdaExecutionRole:
65+
C9LambdaExecutionRole:
5966
Type: AWS::IAM::Role
6067
Properties:
6168
AssumeRolePolicyDocument:
@@ -72,7 +79,7 @@ Resources:
7279
- PolicyName:
7380
Fn::Join:
7481
- ''
75-
- - ExampleC9LambdaPolicy-
82+
- - C9LambdaPolicy-
7683
- Ref: AWS::Region
7784
PolicyDocument:
7885
Version: '2012-10-17'
@@ -99,45 +106,45 @@ Resources:
99106

100107
################## LAMBDA BOOTSTRAP FUNCTION ################
101108

102-
ExampleC9BootstrapInstanceLambda:
109+
C9BootstrapInstanceLambda:
103110
Description: Bootstrap Cloud9 instance
104-
Type: Custom::ExampleC9BootstrapInstanceLambda
111+
Type: Custom::C9BootstrapInstanceLambda
105112
DependsOn:
106-
- ExampleC9BootstrapInstanceLambdaFunction
107-
- ExampleC9Instance
108-
- ExampleC9InstanceProfile
109-
- ExampleC9LambdaExecutionRole
113+
- C9BootstrapInstanceLambdaFunction
114+
- C9Instance
115+
- C9InstanceProfile
116+
- C9LambdaExecutionRole
110117
Properties:
111118
Tags:
112119
- Key: Environment
113-
Value: AWS Example
120+
Value: AWS
114121
ServiceToken:
115122
Fn::GetAtt:
116-
- ExampleC9BootstrapInstanceLambdaFunction
123+
- C9BootstrapInstanceLambdaFunction
117124
- Arn
118125
REGION:
119126
Ref: AWS::Region
120127
StackName:
121128
Ref: AWS::StackName
122129
EnvironmentId:
123-
Ref: ExampleC9Instance
130+
Ref: C9Instance
124131
LabIdeInstanceProfileName:
125-
Ref: ExampleC9InstanceProfile
132+
Ref: C9InstanceProfile
126133
LabIdeInstanceProfileArn:
127134
Fn::GetAtt:
128-
- ExampleC9InstanceProfile
135+
- C9InstanceProfile
129136
- Arn
130137

131-
ExampleC9BootstrapInstanceLambdaFunction:
138+
C9BootstrapInstanceLambdaFunction:
132139
Type: AWS::Lambda::Function
133140
Properties:
134141
Tags:
135142
- Key: Environment
136-
Value: AWS Example
143+
Value: AWS
137144
Handler: index.lambda_handler
138145
Role:
139146
Fn::GetAtt:
140-
- ExampleC9LambdaExecutionRole
147+
- C9LambdaExecutionRole
141148
- Arn
142149
Runtime: python3.9
143150
MemorySize: 256
@@ -202,7 +209,7 @@ Resources:
202209
finally:
203210
cfnresponse.send(event, context, status, responseData, 'CustomResourcePhysicalID')
204211
################## SSM BOOTSRAP HANDLER ###############
205-
ExampleC9OutputBucket:
212+
C9OutputBucket:
206213
Type: AWS::S3::Bucket
207214
DeletionPolicy: Delete
208215
Properties:
@@ -213,20 +220,20 @@ Resources:
213220
- ServerSideEncryptionByDefault:
214221
SSEAlgorithm: AES256
215222

216-
ExampleC9SSMDocument:
223+
C9SSMDocument:
217224
Type: AWS::SSM::Document
218225
Properties:
219226
Tags:
220227
- Key: Environment
221-
Value: AWS Example
228+
Value: AWS
222229
DocumentType: Command
223230
DocumentFormat: YAML
224231
Content:
225232
schemaVersion: '2.2'
226233
description: Bootstrap Cloud9 Instance
227234
mainSteps:
228235
- action: aws:runShellScript
229-
name: ExampleC9bootstrap
236+
name: C9bootstrap
230237
inputs:
231238
runCommand:
232239
- "#!/bin/bash"
@@ -241,7 +248,7 @@ Resources:
241248
- echo '=== INSTALL and CONFIGURE default software components ==='
242249
- sudo -H -u ec2-user bash -c "pip install --user -U boto boto3 botocore awscli"
243250
- echo '=== Resizing the Instance volume'
244-
- !Sub SIZE=${ExampleC9InstanceVolumeSize}
251+
- !Sub SIZE=${C9InstanceVolumeSize}
245252
- !Sub REGION=${AWS::Region}
246253
- |
247254
INSTANCEID=$(curl http://169.254.169.254/latest/meta-data/instance-id)
@@ -293,47 +300,48 @@ Resources:
293300
- FILE=$(mktemp) && echo $FILE && echo '#!/bin/bash' > $FILE && echo 'reboot -f --verbose' >> $FILE && at now + 1 minute -f $FILE
294301
- echo "Bootstrap completed with return code $?"
295302

296-
ExampleC9BootstrapAssociation:
303+
C9BootstrapAssociation:
297304
Type: AWS::SSM::Association
298-
DependsOn: ExampleC9OutputBucket
305+
DependsOn: C9OutputBucket
299306
Properties:
300-
Name: !Ref ExampleC9SSMDocument
307+
Name: !Ref C9SSMDocument
301308
OutputLocation:
302309
S3Location:
303-
OutputS3BucketName: !Ref ExampleC9OutputBucket
310+
OutputS3BucketName: !Ref C9OutputBucket
304311
OutputS3KeyPrefix: bootstrapoutput
305312
Targets:
306313
- Key: tag:SSMBootstrap
307314
Values:
308315
- Active
309316

310317
################## INSTANCE #####################
311-
ExampleC9InstanceProfile:
318+
C9InstanceProfile:
312319
Type: AWS::IAM::InstanceProfile
313320
Properties:
314321
Path: "/"
315322
Roles:
316-
- Ref: ExampleC9Role
323+
- Ref: C9Role
317324

318-
ExampleC9Instance:
325+
C9Instance:
319326
Description: "-"
320-
DependsOn: ExampleC9BootstrapAssociation
327+
DependsOn: C9BootstrapAssociation
321328
Type: AWS::Cloud9::EnvironmentEC2
322329
Properties:
323-
Description: AWS Cloud9 instance for Examples
324-
AutomaticStopTimeMinutes: 3600
330+
Description: AWS Cloud9 instance
331+
AutomaticStopTimeMinutes:
332+
Ref: ShutdownTimeout
325333
InstanceType:
326-
Ref: ExampleC9InstanceType
334+
Ref: C9InstanceType
327335
Name:
328336
Ref: AWS::StackName
329-
OwnerArn: !If [Create3rdPartyResources, !Ref ExampleOwnerArn, !Ref "AWS::NoValue" ]
337+
OwnerArn: !If [Create3rdPartyResources, !Ref OwnerArn, !Ref "AWS::NoValue" ]
330338
Tags:
331339
-
332340
Key: SSMBootstrap
333341
Value: Active
334342
-
335343
Key: Environment
336-
Value: AWS Example
344+
Value: AWS
337345

338346
Outputs:
339347
Cloud9IDE:
@@ -343,6 +351,6 @@ Outputs:
343351
- - https://
344352
- Ref: AWS::Region
345353
- ".console.aws.amazon.com/cloud9/ide/"
346-
- Ref: ExampleC9Instance
354+
- Ref: C9Instance
347355
- "?region="
348356
- Ref: AWS::Region

example_setup.sh cloud9_setup.sh

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
# Simple bash for Workshop C9 Deployment.
33
# will move towards real automation tools later on
44
# created by David Surey, Amazon Web Services
5-
65
# NOT FOR PRODUCTION USE - Only for Workshop purposes
7-
C9STACK="ExampleC9"
6+
C9STACK="C9"
87
PROFILE=$2
98
REGION=$1
109
WORKSHOPUSER="[email protected]"
@@ -25,6 +24,6 @@ fi
2524
echo Building $PROFILE C9
2625

2726
# build the c9 environment
28-
aws cloudformation deploy --stack-name $C9STACK --capabilities CAPABILITY_IAM --template ./example_instancestack.yaml
27+
aws cloudformation deploy --stack-name $C9STACK --capabilities CAPABILITY_IAM --template ./cloud9_instancestack.yaml
2928

3029
exit 0

0 commit comments

Comments
 (0)