This repository was archived by the owner on Mar 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathapp-deployment-cfn.template.yaml
More file actions
93 lines (90 loc) · 3.12 KB
/
Copy pathapp-deployment-cfn.template.yaml
File metadata and controls
93 lines (90 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
AWSTemplateFormatVersion: "2010-09-09"
Description: A CloudFormation template to deploy IoT Application. IoT application is deployed from an EC2 instance launch script and the entire deployment process could take around 30 minutes. After a successfull deployment, a CloudFormation stack is created for the application and this CloudFormation stack will delete iteself. During deployment failure, please see failure reason under DeploymentEC2Instance system log.
Parameters:
ApplicationStackName:
Description: CloudFormation stack name for IoT Application to deploy. Default is IotApp.
Type: String
Default: IotApp
AllowedPattern: "^[a-zA-Z0-9]*$"
MaxLength: 128
MinLength: 1
AuthenticationMode:
Description: Authentication mode of the application. Default is cognito.
Type: String
Default: cognito
AllowedValues:
- cognito
- sso
Mappings:
RegionMap:
us-east-1:
ami: ami-01b799c439fd5516a
us-east-2:
ami: ami-07d7e3e669718ab45
us-west-2:
ami: ami-01572eda7c4411960
ap-south-1:
ami: ami-04f8d7ed2f1a54b14
ap-southeast-1:
ami: ami-008c09a18ce321b3c
ap-southeast-2:
ami: ami-0cb3193ac3a1520ce
ap-northeast-1:
ami: ami-061a125c7c02edb39
eu-central-1:
ami: ami-04f1b917806393faa
eu-west-1:
ami: ami-08ba52a61087f1bd6
Resources:
DeploymentEC2Instance:
Type: AWS::EC2::Instance
Properties:
LaunchTemplate:
LaunchTemplateId: !Ref DeploymentLaunchTemplate
Version: !GetAtt DeploymentLaunchTemplate.DefaultVersionNumber
CreationPolicy:
ResourceSignal:
Timeout: PT45M
DeploymentLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateData:
ImageId: !FindInMap [ RegionMap, !Ref "AWS::Region", ami ]
InstanceType: t3.large
IamInstanceProfile:
Arn: !GetAtt DeploymentEC2InstanceProfile.Arn
BlockDeviceMappings:
- DeviceName: "/dev/xvda"
Ebs:
VolumeSize: 20
UserData:
"Fn::Base64": !Sub |
#!/bin/bash
yum update -y
yum install -y docker
service docker start
yum install -y npm
npm install -g yarn
yum install -y git
git clone https://github.com/awslabs/iot-application.git
cd iot-application/
yarn install
yarn workspace cdk bootstrap
yarn workspace cdk deploy:no-review:${AuthenticationMode} -c stackName=${ApplicationStackName}
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource DeploymentEC2Instance --region ${AWS::Region}
DeploymentEC2InstanceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Action: sts:AssumeRole
Effect: Allow
Principal:
Service: ec2.amazonaws.com
ManagedPolicyArns:
- !Sub "arn:${AWS::Partition}:iam::aws:policy/AdministratorAccess"
DeploymentEC2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles:
- !Ref DeploymentEC2InstanceRole