-
Notifications
You must be signed in to change notification settings - Fork 0
/
EC2_CloudFormation.yaml
167 lines (167 loc) · 4.97 KB
/
EC2_CloudFormation.yaml
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
AWSTemplateFormatVersion: 2010-09-09
Description: >-
AWS CloudFormation Sample Template EC2InstanceWithSecurityGroupSample: Create
an Amazon EC2 instance running the Amazon Linux AMI. The AMI is chosen based
on the region in which the stack is run. This example creates an EC2 security
group for the instance to give you SSH access. **WARNING** This template
creates an Amazon EC2 instance. You will be billed for the AWS resources used
if you create a stack from this template.
Parameters:
KeyName:
Description: Name of an existing EC2 KeyPair to enable SSH access to the instance
Type: "AWS::EC2::KeyPair::KeyName"
ConstraintDescription: must be the name of an existing EC2 KeyPair.
InstanceType:
Description: WebServer EC2 instance type
Type: String
Default: t2.micro
AllowedValues:
- t2.micro
ConstraintDescription: must be a valid EC2 instance type.
SSHLocation:
Description: The IP address range that can be used to SSH to the EC2 instances
Type: String
MinLength: "9"
MaxLength: "18"
Default: 0.0.0.0/0
AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.
Mappings:
AWSInstanceType2Arch:
t2.micro:
Arch: HVM64
AWSInstanceType2NATArch:
t2.micro:
Arch: NATHVM64
AWSRegionArch2AMI:
af-south-1:
HVM64: ami-064cc455f8a1ef504
HVMG2: NOT_SUPPORTED
ap-east-1:
HVM64: ami-f85b1989
HVMG2: NOT_SUPPORTED
ap-northeast-1:
HVM64: ami-0b2c2a754d5b4da22
HVMG2: ami-09d0e0e099ecabba2
ap-northeast-2:
HVM64: ami-0493ab99920f410fc
HVMG2: NOT_SUPPORTED
ap-northeast-3:
HVM64: ami-01344f6f63a4decc1
HVMG2: NOT_SUPPORTED
ap-south-1:
HVM64: ami-03cfb5e1fb4fac428
HVMG2: ami-0244c1d42815af84a
ap-southeast-1:
HVM64: ami-0ba35dc9caf73d1c7
HVMG2: ami-0e46ce0d6a87dc979
ap-southeast-2:
HVM64: ami-0ae99b503e8694028
HVMG2: ami-0c0ab057a101d8ff2
ca-central-1:
HVM64: ami-0803e21a2ec22f953
HVMG2: NOT_SUPPORTED
cn-north-1:
HVM64: ami-07a3f215cc90c889c
HVMG2: NOT_SUPPORTED
cn-northwest-1:
HVM64: ami-0a3b3b10f714a0ff4
HVMG2: NOT_SUPPORTED
eu-central-1:
HVM64: ami-0474863011a7d1541
HVMG2: ami-0aa1822e3eb913a11
eu-north-1:
HVM64: ami-0de4b8910494dba0f
HVMG2: ami-32d55b4c
eu-south-1:
HVM64: ami-08427144fe9ebdef6
HVMG2: NOT_SUPPORTED
eu-west-1:
HVM64: ami-015232c01a82b847b
HVMG2: ami-0d5299b1c6112c3c7
eu-west-2:
HVM64: ami-0765d48d7e15beb93
HVMG2: NOT_SUPPORTED
eu-west-3:
HVM64: ami-0caf07637eda19d9c
HVMG2: NOT_SUPPORTED
me-south-1:
HVM64: ami-0744743d80915b497
HVMG2: NOT_SUPPORTED
sa-east-1:
HVM64: ami-0a52e8a6018e92bb0
HVMG2: NOT_SUPPORTED
us-east-1:
HVM64: ami-032930428bf1abbff
HVMG2: ami-0aeb704d503081ea6
us-east-2:
HVM64: ami-027cab9a7bf0155df
HVMG2: NOT_SUPPORTED
us-west-1:
HVM64: ami-088c153f74339f34c
HVMG2: ami-0a7fc72dc0e51aa77
us-west-2:
HVM64: ami-01fee56b22f308154
HVMG2: ami-0fe84a5b4563d8f27
Resources:
InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: "/"
Roles: ["LabRole"]
EC2Instance:
Type: "AWS::EC2::Instance"
Properties:
InstanceType: t2.micro
SecurityGroups:
- !Ref InstanceSecurityGroup
KeyName: !Ref KeyName
ImageId: !FindInMap
- AWSRegionArch2AMI
- !Ref "AWS::Region"
- !FindInMap
- AWSInstanceType2Arch
- !Ref "InstanceType"
- Arch
IamInstanceProfile: !Ref "InstanceProfile"
UserData: !Base64 |
#!/bin/bash -xe
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo yum install -y nodejs git
aws s3 cp s3://frontend-bucket-jk/FrontendArchive.zip /home/ec2-user/
unzip /home/ec2-user/FrontendArchive.zip -d /home/ec2-user/FrontendCode
cd /home/ec2-user/FrontendCode
npm install
npm start
InstanceSecurityGroup:
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: !Ref SSHLocation
- IpProtocol: tcp
FromPort: 3000
ToPort: 3000
CidrIp: 0.0.0.0/0
Outputs:
InstanceId:
Description: InstanceId of the newly created EC2 instance
Value: !Ref EC2Instance
AZ:
Description: Availability Zone of the newly created EC2 instance
Value: !GetAtt
- EC2Instance
- AvailabilityZone
PublicDNS:
Description: Public DNSName of the newly created EC2 instance
Value: !GetAtt
- EC2Instance
- PublicDnsName
PublicIP:
Description: Public IP address of the newly created EC2 instance
Value: !GetAtt
- EC2Instance
- PublicIp