Huh Jin-Ho

add infra code

Showing 131 changed files with 30523 additions and 1 deletions
infra_code @ 5fffd3a4
1 -Subproject commit 5fffd3a4f66d68db249c923f44c48b6d84f798b8
No preview for this file type
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +## 전제사항
4 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
5 +* CodeDeploy, CloudWatch Agent 설치된 AMI
6 + * AMI 없이 UserData로 설치 가능
7 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
8 + * AMI 없이 UserData로 설치 가능
9 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
10 +
11 +## 자동 배포 진행 과정
12 +
13 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
14 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
15 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
16 +
17 +# CloudFormation 인프라 구성
18 +
19 +* ### json 또는 yaml 형식으로 인프라 정의
20 +```yaml
21 +Parameters:
22 + KeyName:
23 + Type: String
24 + Default: dd
25 + WebappSubnets:
26 + Type: CommaDelimitedList
27 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
28 + ALBSubnets:
29 + Type: CommaDelimitedList
30 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
31 + MinSize:
32 + Type: Number
33 + Default: 2
34 + MaxSize:
35 + Type: Number
36 + Default: 3
37 + VPC:
38 + Type: String
39 + Default: vpc-aab1aac2
40 + AMIID:
41 + Type: String
42 + Default: ami-08ab3f7e72215fe91
43 + NamePrefix:
44 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
45 + Default: bluegreen
46 + Description: Prefix for resource tags made by this template (2-15 chars).
47 + MaxLength: 15
48 + MinLength: 2
49 + Type: String
50 +```
51 +```yaml
52 +Resources:
53 + CodeDeployRole:
54 + Type: "AWS::IAM::Role"
55 + Properties:
56 + AssumeRolePolicyDocument:
57 + Version: "2012-10-17"
58 + Statement:
59 + -
60 + Effect: "Allow"
61 + Principal:
62 + Service:
63 + - "codedeploy.amazonaws.com"
64 + Action:
65 + - "sts:AssumeRole"
66 + Policies:
67 + -
68 + PolicyName: allow-autoscaling
69 + PolicyDocument:
70 + Version: "2012-10-17"
71 + Statement:
72 + -
73 + Effect: Allow
74 + Action:
75 + - ec2:*
76 + - autoscaling:*
77 + Resource: "*"
78 + -
79 + PolicyName: allow-loadbalance
80 + PolicyDocument:
81 + Version: "2012-10-17"
82 + Statement:
83 + -
84 + Effect: Allow
85 + Action:
86 + - ec2:*
87 + - autoscaling:*
88 + Resource: "*"
89 + -
90 + Effect: Allow
91 + Action:
92 + - iam:CreateServiceLinkedRole
93 + Resource: "*"
94 + -
95 + Effect: Allow
96 + Action:
97 + - elasticloadbalancing:*
98 + Resource: "*"
99 + WebappRole:
100 + Type: "AWS::IAM::Role"
101 + Properties:
102 + AssumeRolePolicyDocument:
103 + Version: "2012-10-17"
104 + Statement:
105 + -
106 + Effect: "Allow"
107 + Principal:
108 + Service:
109 + - "ec2.amazonaws.com"
110 + - "codedeploy.amazonaws.com"
111 + - "events.amazonaws.com"
112 + Action:
113 + - "sts:AssumeRole"
114 + Policies:
115 + -
116 + PolicyName: "allow-webapp-deployment-bucket-bucket"
117 + PolicyDocument:
118 + Version: "2012-10-17"
119 + Statement:
120 + -
121 + Effect: "Allow"
122 + Action: "s3:getObject"
123 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
124 + -
125 + Effect: Allow
126 + Action:
127 + - autoscaling:*
128 + - cloudwatch:*
129 + - logs:*
130 + - sns:*
131 + Resource: "*"
132 + WebappInstanceProfile:
133 + Type: "AWS::IAM::InstanceProfile"
134 + Properties:
135 + Roles:
136 + - Ref: WebappRole
137 + ALBSecurityGroup:
138 + Type: AWS::EC2::SecurityGroup
139 + Properties:
140 + GroupDescription: allow access to ALB from internet
141 + VpcId:
142 + Ref: VPC
143 + SecurityGroupIngress:
144 + - IpProtocol: tcp
145 + FromPort: '80'
146 + ToPort: '80'
147 + CidrIp: 0.0.0.0/0
148 + WebappSecurityGroup:
149 + Type: AWS::EC2::SecurityGroup
150 + Properties:
151 + GroupDescription: allow access to Webapp from ALB
152 + VpcId:
153 + Ref: VPC
154 + SecurityGroupIngress:
155 + - IpProtocol: tcp
156 + FromPort: '3000'
157 + ToPort: '3000'
158 + SourceSecurityGroupId:
159 + Ref: ALBSecurityGroup
160 + - IpProtocol: tcp
161 + FromPort: '22'
162 + ToPort: '22'
163 + CidrIp: 0.0.0.0/0
164 + WebappLaunchConfig:
165 + Type: AWS::AutoScaling::LaunchConfiguration
166 + Properties:
167 + AssociatePublicIpAddress: true
168 + ImageId:
169 + Ref: AMIID
170 + InstanceType: t2.micro
171 + KeyName:
172 + Ref: KeyName
173 + SecurityGroups:
174 + - Ref: WebappSecurityGroup
175 + IamInstanceProfile:
176 + Ref: WebappInstanceProfile
177 + UserData:
178 + Fn::Base64:
179 + !Sub |
180 + #! /bin/bash -xe
181 + # update yum just in case
182 + yum update -y
183 + # install codedeploy agent
184 + yum install -y ruby
185 + yum install -y wget
186 + cd /home/ec2-user
187 + # you have to notice region in url
188 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
189 + chmod +x ./install
190 + ./install auto
191 + # install cloudwatch logs agent
192 + sudo yum install -y awslogs
193 + # set config file sending log to right region
194 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
195 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
196 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
197 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
198 + # start cloudwatch agent
199 + sudo systemctl start awslogsd
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 + WebappApplication:
265 + Type: "AWS::CodeDeploy::Application"
266 + Properties:
267 + ApplicationName: testApp
268 + WebappDeploymentGroup:
269 + Type: "AWS::CodeDeploy::DeploymentGroup"
270 + Properties:
271 + DeploymentGroupName: test-group
272 + ApplicationName: !Ref WebappApplication
273 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
274 + DeploymentConfigName: CodeDeployDefault.OneAtATime
275 + DeploymentStyle:
276 + DeploymentType: IN_PLACE
277 + DeploymentOption: WITH_TRAFFIC_CONTROL
278 + LoadBalancerInfo:
279 + TargetGroupInfoList:
280 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
281 + AutoScalingGroups:
282 + - Ref: AutoScalingGroup
283 + WebappDeploymentBucket:
284 + Type: "AWS::S3::Bucket"
285 + Properties:
286 + BucketName: 'testtest11324'
287 +```
288 +```yaml
289 +Outputs:
290 + WebappUrl:
291 + Description: Webapp URL
292 + Value: !GetAtt LoadBalancer.DNSName
293 + DeploymentGroup:
294 + Description: Webapp Deployment Group
295 + Value: !Ref WebappDeploymentGroup
296 + DeploymentBucket:
297 + Description: Deployment bucket
298 + Value: !Ref WebappDeploymentBucket
299 + ApplicationName:
300 + Description: CodeDeploy Application name
301 + Value: !Ref WebappApplication
302 +```
303 +* ### Cloudformation 스택 생성
304 +```
305 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
306 +```
307 +* ### Cloudformation 스택 업데이트
308 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
309 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
310 +```
311 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
312 +```
313 +* ### Cloudformation 스택 삭제
314 +```
315 +$ aws cloudformation delete-stack --stack-name test-template-1
316 +```
317 +
318 +# 빌드 파일 S3 전송
319 +```
320 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
321 +```
322 +
323 +# 빌드된 파일 배포
324 +
325 +## 배포 방식 종류
326 +* ### In Place 방식
327 + * 기존에 존재하는 인스턴스에 배포하는 방식
328 +* ### Blue / Green 방식
329 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
330 +
331 +## LoadBalancer로 트래픽 분배
332 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
333 +
334 +## appspec.yml 설정
335 +```
336 +version: 0.0
337 +os: linux
338 +files:
339 + - source: src
340 + destination: /opt/webapp
341 + - source: node_modules
342 + destination: /opt/webapp/node_modules
343 +hooks:
344 + ApplicationStop:
345 + - location: deployment_scripts/stop.sh
346 + timeout: 180
347 + AfterInstall:
348 + - location: deployment_scripts/deploy.sh
349 + timeout: 180
350 + ApplicationStart:
351 + - location: deployment_scripts/start.sh
352 + timeout: 180
353 +
354 +```
355 +* ### start.sh
356 +```
357 +#!/usr/bin/env bash
358 +
359 +sudo pm2 stop node-app
360 +# actually start the server
361 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
362 +```
363 +* ### stop.sh
364 +```
365 +#!/usr/bin/env bash
366 +
367 +sudo pm2 stop node-app
368 +sleep 10
369 +```
370 +
371 +
372 +## 명령어
373 +```
374 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
375 +```
376 +
377 +# 배포 관련 로그 확인
378 +
379 +## CloudWatch Logs 관련 설정 파일
380 +```
381 +#/etc/awslogs/awscli.conf
382 +
383 +[plugins]
384 +cwlogs = cwlogs
385 +[default] ## plugin 지정
386 +region = ap-northeast-2 ## cloudwatch region 지정
387 +```
388 +
389 +```
390 +#/etc/awslogs/awslogs.conf
391 +
392 +[general] ## general 없을 시 오류 발생
393 +datetime_format = %Y-%m-%d %H:%M:%S
394 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
395 +log_stream_name = {instance_id}-codedeploy-agent-log
396 +log_group_name = codedeploy-agent-log
397 +
398 +[codedeploy-agent-logs]
399 +datetime_format = %Y-%m-%d %H:%M:%S
400 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
401 +log_stream_name = {instance_id}-codedeploy-agent-log
402 +log_group_name = codedeploy-agent-log
403 +
404 +[codedeploy-updater-logs]
405 +file = /tmp/codedeploy-agent.update.log
406 +log_stream_name = {instance_id}-codedeploy-updater-log
407 +log_group_name = codedeploy-updater-log
408 +
409 +[codedeploy-deployment-logs]
410 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
411 +log_stream_name = {instance_id}-codedeploy-deployments-log
412 +log_group_name = codedeploy-deployments-log
413 +```
414 +* applicaion 로그도 해당 형식으로 입력 시 확인 가능
415 +
416 +* ## CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
417 +```
418 +var/log/awslogs.log
419 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +## 전제사항
4 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
5 +* CodeDeploy, CloudWatch Agent 설치된 AMI
6 + * AMI 없이 UserData로 설치 가능
7 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
8 + * AMI 없이 UserData로 설치 가능
9 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
10 +
11 +## 자동 배포 진행 과정
12 +
13 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
14 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
15 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
16 +
17 +# CloudFormation 인프라 구성
18 +
19 +* ### json 또는 yaml 형식으로 인프라 정의
20 + * 파라미터
21 +```yaml
22 +Parameters:
23 + KeyName:
24 + Type: String
25 + Default: dd
26 + WebappSubnets:
27 + Type: CommaDelimitedList
28 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
29 + ALBSubnets:
30 + Type: CommaDelimitedList
31 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
32 + MinSize:
33 + Type: Number
34 + Default: 2
35 + MaxSize:
36 + Type: Number
37 + Default: 3
38 + VPC:
39 + Type: String
40 + Default: vpc-aab1aac2
41 + AMIID:
42 + Type: String
43 + Default: ami-08ab3f7e72215fe91
44 + NamePrefix:
45 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
46 + Default: bluegreen
47 + Description: Prefix for resource tags made by this template (2-15 chars).
48 + MaxLength: 15
49 + MinLength: 2
50 + Type: String
51 +```
52 + * role 설정
53 + * codedeploy가 loadbalancer와 autoscaling을 이용할 수 있도록 하는 설정
54 + * Instance가 cloudwatch와 codedeploy를 이용하고 s3로부터 코드를 가져올 수 있도록 하는 설정
55 +```yaml
56 +Resources:
57 + CodeDeployRole:
58 + Type: "AWS::IAM::Role"
59 + Properties:
60 + AssumeRolePolicyDocument:
61 + Version: "2012-10-17"
62 + Statement:
63 + -
64 + Effect: "Allow"
65 + Principal:
66 + Service:
67 + - "codedeploy.amazonaws.com"
68 + Action:
69 + - "sts:AssumeRole"
70 + Policies:
71 + -
72 + PolicyName: allow-autoscaling
73 + PolicyDocument:
74 + Version: "2012-10-17"
75 + Statement:
76 + -
77 + Effect: Allow
78 + Action:
79 + - ec2:*
80 + - autoscaling:*
81 + Resource: "*"
82 + -
83 + PolicyName: allow-loadbalance
84 + PolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: Allow
89 + Action:
90 + - ec2:*
91 + - autoscaling:*
92 + Resource: "*"
93 + -
94 + Effect: Allow
95 + Action:
96 + - iam:CreateServiceLinkedRole
97 + Resource: "*"
98 + -
99 + Effect: Allow
100 + Action:
101 + - elasticloadbalancing:*
102 + Resource: "*"
103 + WebappRole:
104 + Type: "AWS::IAM::Role"
105 + Properties:
106 + AssumeRolePolicyDocument:
107 + Version: "2012-10-17"
108 + Statement:
109 + -
110 + Effect: "Allow"
111 + Principal:
112 + Service:
113 + - "ec2.amazonaws.com"
114 + - "codedeploy.amazonaws.com"
115 + - "events.amazonaws.com"
116 + Action:
117 + - "sts:AssumeRole"
118 + Policies:
119 + -
120 + PolicyName: "allow-webapp-deployment-bucket-bucket"
121 + PolicyDocument:
122 + Version: "2012-10-17"
123 + Statement:
124 + -
125 + Effect: "Allow"
126 + Action: "s3:getObject"
127 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
128 + -
129 + Effect: Allow
130 + Action:
131 + - autoscaling:*
132 + - cloudwatch:*
133 + - logs:*
134 + - sns:*
135 + Resource: "*"
136 +```
137 + * 인프라 정의
138 + * security Group
139 + * autoscaling group
140 + * loadbalancer
141 +```yaml
142 + WebappInstanceProfile:
143 + Type: "AWS::IAM::InstanceProfile"
144 + Properties:
145 + Roles:
146 + - Ref: WebappRole
147 + ALBSecurityGroup:
148 + Type: AWS::EC2::SecurityGroup
149 + Properties:
150 + GroupDescription: allow access to ALB from internet
151 + VpcId:
152 + Ref: VPC
153 + SecurityGroupIngress:
154 + - IpProtocol: tcp
155 + FromPort: '80'
156 + ToPort: '80'
157 + CidrIp: 0.0.0.0/0
158 + WebappSecurityGroup:
159 + Type: AWS::EC2::SecurityGroup
160 + Properties:
161 + GroupDescription: allow access to Webapp from ALB
162 + VpcId:
163 + Ref: VPC
164 + SecurityGroupIngress:
165 + - IpProtocol: tcp
166 + FromPort: '3000'
167 + ToPort: '3000'
168 + SourceSecurityGroupId:
169 + Ref: ALBSecurityGroup
170 + - IpProtocol: tcp
171 + FromPort: '22'
172 + ToPort: '22'
173 + CidrIp: 0.0.0.0/0
174 + WebappLaunchConfig:
175 + Type: AWS::AutoScaling::LaunchConfiguration
176 + Properties:
177 + AssociatePublicIpAddress: true
178 + ImageId:
179 + Ref: AMIID
180 + InstanceType: t2.micro
181 + KeyName:
182 + Ref: KeyName
183 + SecurityGroups:
184 + - Ref: WebappSecurityGroup
185 + IamInstanceProfile:
186 + Ref: WebappInstanceProfile
187 + UserData:
188 + Fn::Base64:
189 + !Sub |
190 + #! /bin/bash -xe
191 + # update yum just in case
192 + yum update -y
193 + # install codedeploy agent
194 + yum install -y ruby
195 + yum install -y wget
196 + cd /home/ec2-user
197 + # you have to notice region in url
198 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
199 + chmod +x ./install
200 + ./install auto
201 + # install cloudwatch logs agent
202 + sudo yum install -y awslogs
203 + # set config file sending log to right region
204 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
205 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
206 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
207 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
208 + # start cloudwatch agent
209 + sudo systemctl start awslogsd
210 + # get node into yum
211 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
212 + # install node and npm in one line
213 + yum install -y nodejs
214 + # install pm2 to restart node app
215 + npm i -g pm2@2.4.3
216 + AutoScalingGroup:
217 + Type: AWS::AutoScaling::AutoScalingGroup
218 + Properties:
219 + HealthCheckType: ELB
220 + HealthCheckGracePeriod: 300
221 + MinSize:
222 + Ref: MinSize
223 + MaxSize:
224 + Ref: MaxSize
225 + LaunchConfigurationName:
226 + Ref: WebappLaunchConfig
227 + VPCZoneIdentifier:
228 + Ref: WebappSubnets
229 + TargetGroupARNs:
230 + - Ref: ALBTargetGroup
231 + Tags:
232 + - Key: Name
233 + Value: webapp-example
234 + PropagateAtLaunch: true
235 + ALBListener:
236 + Type: AWS::ElasticLoadBalancingV2::Listener
237 + Properties:
238 + DefaultActions:
239 + -
240 + Type: forward
241 + TargetGroupArn:
242 + Ref: ALBTargetGroup
243 + LoadBalancerArn:
244 + Ref: LoadBalancer
245 + Port: 80
246 + Protocol: HTTP
247 + LoadBalancer:
248 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
249 + Properties:
250 + Name: testLoadbalancer
251 + Scheme: internet-facing
252 + Subnets:
253 + Ref: ALBSubnets
254 + SecurityGroups:
255 + - Ref: ALBSecurityGroup
256 + Tags:
257 + - Key: Name
258 + Value:
259 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
260 + ALBTargetGroup:
261 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
262 + Properties:
263 + TargetGroupAttributes:
264 + - Key: deregistration_delay.timeout_seconds
265 + Value: 30
266 + HealthCheckIntervalSeconds: 30
267 + UnhealthyThresholdCount: 2
268 + HealthyThresholdCount: 2
269 + HealthCheckPath: /
270 + Port: 3000
271 + Protocol: HTTP
272 + VpcId:
273 + Ref: VPC
274 +```
275 + * codedeploy 설정
276 + * codedeploy application을 설정
277 + * codedeploy group을 이용하여 세부 배포 설정
278 +```yaml
279 + WebappApplication:
280 + Type: "AWS::CodeDeploy::Application"
281 + Properties:
282 + ApplicationName: testApp
283 + WebappDeploymentGroup:
284 + Type: "AWS::CodeDeploy::DeploymentGroup"
285 + Properties:
286 + DeploymentGroupName: test-group
287 + ApplicationName: !Ref WebappApplication
288 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
289 + DeploymentConfigName: CodeDeployDefault.OneAtATime
290 + DeploymentStyle:
291 + DeploymentType: IN_PLACE
292 + DeploymentOption: WITH_TRAFFIC_CONTROL
293 + LoadBalancerInfo:
294 + TargetGroupInfoList:
295 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
296 + AutoScalingGroups:
297 + - Ref: AutoScalingGroup
298 + WebappDeploymentBucket:
299 + Type: "AWS::S3::Bucket"
300 + Properties:
301 + BucketName: 'testtest11324'
302 +```
303 +* output 설정
304 + * loadbalancer dns와 같이 인프라 생성이후에 정의되는 변수들을 출력하여 굳이 콘솔에서 로드밸런서 주소를 확인하지 않아도 된다
305 +```yaml
306 +Outputs:
307 + WebappUrl:
308 + Description: Webapp URL
309 + Value: !GetAtt LoadBalancer.DNSName
310 + DeploymentGroup:
311 + Description: Webapp Deployment Group
312 + Value: !Ref WebappDeploymentGroup
313 + DeploymentBucket:
314 + Description: Deployment bucket
315 + Value: !Ref WebappDeploymentBucket
316 + ApplicationName:
317 + Description: CodeDeploy Application name
318 + Value: !Ref WebappApplication
319 +```
320 +* ### Cloudformation 스택 생성
321 +```
322 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
323 +```
324 +* ### Cloudformation 스택 업데이트
325 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
326 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
327 +```
328 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
329 +```
330 +* ### Cloudformation 스택 삭제
331 +```
332 +$ aws cloudformation delete-stack --stack-name test-template-1
333 +```
334 +
335 +# 빌드 파일 S3 전송
336 +```
337 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
338 +```
339 +
340 +# 빌드된 파일 배포
341 +
342 +## 배포 방식 종류
343 +* ### In Place 방식
344 + * 기존에 존재하는 인스턴스에 배포하는 방식
345 +* ### Blue / Green 방식
346 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
347 +
348 +## LoadBalancer로 트래픽 분배
349 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
350 +
351 +## appspec.yml 설정
352 +```
353 +version: 0.0
354 +os: linux
355 +files:
356 + - source: src
357 + destination: /opt/webapp
358 + - source: node_modules
359 + destination: /opt/webapp/node_modules
360 +hooks:
361 + ApplicationStop:
362 + - location: deployment_scripts/stop.sh
363 + timeout: 180
364 + AfterInstall:
365 + - location: deployment_scripts/deploy.sh
366 + timeout: 180
367 + ApplicationStart:
368 + - location: deployment_scripts/start.sh
369 + timeout: 180
370 +
371 +```
372 +* ### start.sh
373 +```
374 +#!/usr/bin/env bash
375 +
376 +sudo pm2 stop node-app
377 +# actually start the server
378 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
379 +```
380 +* ### stop.sh
381 +```
382 +#!/usr/bin/env bash
383 +
384 +sudo pm2 stop node-app
385 +sleep 10
386 +```
387 +
388 +
389 +## 명령어
390 +```
391 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
392 +```
393 +
394 +# 배포 관련 로그 확인
395 +
396 +## CloudWatch Logs 관련 설정 파일
397 +```
398 +#/etc/awslogs/awscli.conf
399 +
400 +[plugins]
401 +cwlogs = cwlogs
402 +[default] ## plugin 지정
403 +region = ap-northeast-2 ## cloudwatch region 지정
404 +```
405 +
406 +```
407 +#/etc/awslogs/awslogs.conf
408 +
409 +[general] ## general 없을 시 오류 발생
410 +datetime_format = %Y-%m-%d %H:%M:%S
411 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
412 +log_stream_name = {instance_id}-codedeploy-agent-log
413 +log_group_name = codedeploy-agent-log
414 +
415 +[codedeploy-agent-logs]
416 +datetime_format = %Y-%m-%d %H:%M:%S
417 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
418 +log_stream_name = {instance_id}-codedeploy-agent-log
419 +log_group_name = codedeploy-agent-log
420 +
421 +[codedeploy-updater-logs]
422 +file = /tmp/codedeploy-agent.update.log
423 +log_stream_name = {instance_id}-codedeploy-updater-log
424 +log_group_name = codedeploy-updater-log
425 +
426 +[codedeploy-deployment-logs]
427 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
428 +log_stream_name = {instance_id}-codedeploy-deployments-log
429 +log_group_name = codedeploy-deployments-log
430 +```
431 +* applicaion 로그도 해당 형식으로 입력 시 확인 가능
432 +
433 +* ## CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
434 +```
435 +var/log/awslogs.log
436 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +## 전제사항
4 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
5 +* CodeDeploy, CloudWatch Agent 설치된 AMI
6 + * AMI 없이 UserData로 설치 가능
7 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
8 + * AMI 없이 UserData로 설치 가능
9 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
10 +
11 +## 자동 배포 진행 과정
12 +
13 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
14 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
15 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
16 +
17 +# CloudFormation 인프라 구성
18 +
19 +* ### json 또는 yaml 형식으로 인프라 정의
20 + * 파라미터
21 +```yaml
22 +Parameters:
23 + KeyName:
24 + Type: String
25 + Default: dd
26 + WebappSubnets:
27 + Type: CommaDelimitedList
28 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
29 + ALBSubnets:
30 + Type: CommaDelimitedList
31 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
32 + MinSize:
33 + Type: Number
34 + Default: 2
35 + MaxSize:
36 + Type: Number
37 + Default: 3
38 + VPC:
39 + Type: String
40 + Default: vpc-aab1aac2
41 + AMIID:
42 + Type: String
43 + Default: ami-08ab3f7e72215fe91
44 + NamePrefix:
45 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
46 + Default: bluegreen
47 + Description: Prefix for resource tags made by this template (2-15 chars).
48 + MaxLength: 15
49 + MinLength: 2
50 + Type: String
51 +```
52 + * role 설정
53 + * codedeploy가 loadbalancer와 autoscaling을 이용할 수 있도록 하는 설정
54 + * Instance가 cloudwatch와 codedeploy를 이용하고 s3로부터 코드를 가져올 수 있도록 하는 설정
55 +```yaml
56 +Resources:
57 + CodeDeployRole:
58 + Type: "AWS::IAM::Role"
59 + Properties:
60 + AssumeRolePolicyDocument:
61 + Version: "2012-10-17"
62 + Statement:
63 + -
64 + Effect: "Allow"
65 + Principal:
66 + Service:
67 + - "codedeploy.amazonaws.com"
68 + Action:
69 + - "sts:AssumeRole"
70 + Policies:
71 + -
72 + PolicyName: allow-autoscaling
73 + PolicyDocument:
74 + Version: "2012-10-17"
75 + Statement:
76 + -
77 + Effect: Allow
78 + Action:
79 + - ec2:*
80 + - autoscaling:*
81 + Resource: "*"
82 + -
83 + PolicyName: allow-loadbalance
84 + PolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: Allow
89 + Action:
90 + - ec2:*
91 + - autoscaling:*
92 + Resource: "*"
93 + -
94 + Effect: Allow
95 + Action:
96 + - iam:CreateServiceLinkedRole
97 + Resource: "*"
98 + -
99 + Effect: Allow
100 + Action:
101 + - elasticloadbalancing:*
102 + Resource: "*"
103 + WebappRole:
104 + Type: "AWS::IAM::Role"
105 + Properties:
106 + AssumeRolePolicyDocument:
107 + Version: "2012-10-17"
108 + Statement:
109 + -
110 + Effect: "Allow"
111 + Principal:
112 + Service:
113 + - "ec2.amazonaws.com"
114 + - "codedeploy.amazonaws.com"
115 + - "events.amazonaws.com"
116 + Action:
117 + - "sts:AssumeRole"
118 + Policies:
119 + -
120 + PolicyName: "allow-webapp-deployment-bucket-bucket"
121 + PolicyDocument:
122 + Version: "2012-10-17"
123 + Statement:
124 + -
125 + Effect: "Allow"
126 + Action: "s3:getObject"
127 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
128 + -
129 + Effect: Allow
130 + Action:
131 + - autoscaling:*
132 + - cloudwatch:*
133 + - logs:*
134 + - sns:*
135 + Resource: "*"
136 +```
137 + * 인프라 정의
138 + * security Group
139 + * autoscaling group
140 + * loadbalancer
141 +```yaml
142 + WebappInstanceProfile:
143 + Type: "AWS::IAM::InstanceProfile"
144 + Properties:
145 + Roles:
146 + - Ref: WebappRole
147 + ALBSecurityGroup:
148 + Type: AWS::EC2::SecurityGroup
149 + Properties:
150 + GroupDescription: allow access to ALB from internet
151 + VpcId:
152 + Ref: VPC
153 + SecurityGroupIngress:
154 + - IpProtocol: tcp
155 + FromPort: '80'
156 + ToPort: '80'
157 + CidrIp: 0.0.0.0/0
158 + WebappSecurityGroup:
159 + Type: AWS::EC2::SecurityGroup
160 + Properties:
161 + GroupDescription: allow access to Webapp from ALB
162 + VpcId:
163 + Ref: VPC
164 + SecurityGroupIngress:
165 + - IpProtocol: tcp
166 + FromPort: '3000'
167 + ToPort: '3000'
168 + SourceSecurityGroupId:
169 + Ref: ALBSecurityGroup
170 + - IpProtocol: tcp
171 + FromPort: '22'
172 + ToPort: '22'
173 + CidrIp: 0.0.0.0/0
174 + WebappLaunchConfig:
175 + Type: AWS::AutoScaling::LaunchConfiguration
176 + Properties:
177 + AssociatePublicIpAddress: true
178 + ImageId:
179 + Ref: AMIID
180 + InstanceType: t2.micro
181 + KeyName:
182 + Ref: KeyName
183 + SecurityGroups:
184 + - Ref: WebappSecurityGroup
185 + IamInstanceProfile:
186 + Ref: WebappInstanceProfile
187 + UserData:
188 + Fn::Base64:
189 + !Sub |
190 + #! /bin/bash -xe
191 + # update yum just in case
192 + yum update -y
193 + # install codedeploy agent
194 + yum install -y ruby
195 + yum install -y wget
196 + cd /home/ec2-user
197 + # you have to notice region in url
198 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
199 + chmod +x ./install
200 + ./install auto
201 + # install cloudwatch logs agent
202 + sudo yum install -y awslogs
203 + # set config file sending log to right region
204 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
205 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
206 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
207 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
208 + # start cloudwatch agent
209 + sudo systemctl start awslogsd
210 + # get node into yum
211 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
212 + # install node and npm in one line
213 + yum install -y nodejs
214 + # install pm2 to restart node app
215 + npm i -g pm2@2.4.3
216 + AutoScalingGroup:
217 + Type: AWS::AutoScaling::AutoScalingGroup
218 + Properties:
219 + HealthCheckType: ELB
220 + HealthCheckGracePeriod: 300
221 + MinSize:
222 + Ref: MinSize
223 + MaxSize:
224 + Ref: MaxSize
225 + LaunchConfigurationName:
226 + Ref: WebappLaunchConfig
227 + VPCZoneIdentifier:
228 + Ref: WebappSubnets
229 + TargetGroupARNs:
230 + - Ref: ALBTargetGroup
231 + Tags:
232 + - Key: Name
233 + Value: webapp-example
234 + PropagateAtLaunch: true
235 + ALBListener:
236 + Type: AWS::ElasticLoadBalancingV2::Listener
237 + Properties:
238 + DefaultActions:
239 + -
240 + Type: forward
241 + TargetGroupArn:
242 + Ref: ALBTargetGroup
243 + LoadBalancerArn:
244 + Ref: LoadBalancer
245 + Port: 80
246 + Protocol: HTTP
247 + LoadBalancer:
248 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
249 + Properties:
250 + Name: testLoadbalancer
251 + Scheme: internet-facing
252 + Subnets:
253 + Ref: ALBSubnets
254 + SecurityGroups:
255 + - Ref: ALBSecurityGroup
256 + Tags:
257 + - Key: Name
258 + Value:
259 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
260 + ALBTargetGroup:
261 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
262 + Properties:
263 + TargetGroupAttributes:
264 + - Key: deregistration_delay.timeout_seconds
265 + Value: 30
266 + HealthCheckIntervalSeconds: 30
267 + UnhealthyThresholdCount: 2
268 + HealthyThresholdCount: 2
269 + HealthCheckPath: /
270 + Port: 3000
271 + Protocol: HTTP
272 + VpcId:
273 + Ref: VPC
274 +```
275 + * codedeploy 설정
276 + * codedeploy application을 설정
277 + * codedeploy group을 이용하여 세부 배포 설정
278 +```yaml
279 + WebappApplication:
280 + Type: "AWS::CodeDeploy::Application"
281 + Properties:
282 + ApplicationName: testApp
283 + WebappDeploymentGroup:
284 + Type: "AWS::CodeDeploy::DeploymentGroup"
285 + Properties:
286 + DeploymentGroupName: test-group
287 + ApplicationName: !Ref WebappApplication
288 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
289 + DeploymentConfigName: CodeDeployDefault.OneAtATime
290 + DeploymentStyle:
291 + DeploymentType: IN_PLACE
292 + DeploymentOption: WITH_TRAFFIC_CONTROL
293 + LoadBalancerInfo:
294 + TargetGroupInfoList:
295 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
296 + AutoScalingGroups:
297 + - Ref: AutoScalingGroup
298 + WebappDeploymentBucket:
299 + Type: "AWS::S3::Bucket"
300 + Properties:
301 + BucketName: 'testtest11324'
302 +```
303 +* output 설정
304 + * loadbalancer dns와 같이 인프라 생성이후에 정의되는 변수들을 출력하여 굳이 콘솔에서 로드밸런서 주소를 확인하지 않아도 된다
305 +```yaml
306 +Outputs:
307 + WebappUrl:
308 + Description: Webapp URL
309 + Value: !GetAtt LoadBalancer.DNSName
310 + DeploymentGroup:
311 + Description: Webapp Deployment Group
312 + Value: !Ref WebappDeploymentGroup
313 + DeploymentBucket:
314 + Description: Deployment bucket
315 + Value: !Ref WebappDeploymentBucket
316 + ApplicationName:
317 + Description: CodeDeploy Application name
318 + Value: !Ref WebappApplication
319 +```
320 +* ### Cloudformation 스택 생성
321 +```
322 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
323 +```
324 +* ### Cloudformation 스택 업데이트
325 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
326 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
327 +```
328 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
329 +```
330 +* ### Cloudformation 스택 삭제
331 +```
332 +$ aws cloudformation delete-stack --stack-name test-template-1
333 +```
334 +
335 +# 빌드 파일 S3 전송
336 +```
337 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
338 +```
339 +
340 +# 빌드된 파일 배포
341 +
342 +## 배포 방식 종류
343 +* ### In Place 방식
344 + * 기존에 존재하는 인스턴스에 배포하는 방식
345 +* ### Blue / Green 방식
346 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
347 +
348 +## LoadBalancer로 트래픽 분배
349 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
350 +
351 +## appspec.yml 설정
352 +```
353 +version: 0.0
354 +os: linux
355 +files:
356 + - source: src
357 + destination: /opt/webapp
358 + - source: node_modules
359 + destination: /opt/webapp/node_modules
360 +hooks:
361 + ApplicationStop:
362 + - location: deployment_scripts/stop.sh
363 + timeout: 180
364 + AfterInstall:
365 + - location: deployment_scripts/deploy.sh
366 + timeout: 180
367 + ApplicationStart:
368 + - location: deployment_scripts/start.sh
369 + timeout: 180
370 +
371 +```
372 +* ### start.sh
373 +```
374 +#!/usr/bin/env bash
375 +
376 +sudo pm2 stop node-app
377 +# actually start the server
378 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
379 +```
380 +* ### stop.sh
381 +```
382 +#!/usr/bin/env bash
383 +
384 +sudo pm2 stop node-app
385 +sleep 10
386 +```
387 +
388 +
389 +## 명령어
390 +```
391 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
392 +```
393 +
394 +# 배포 관련 로그 확인
395 +
396 +## CloudWatch Logs 관련 설정 파일
397 +* UserData 설정
398 +```yaml
399 +UserData:
400 + Fn::Base64:
401 + !Sub |
402 + #! /bin/bash -xe
403 + # update yum just in case
404 + yum update -y
405 + # install codedeploy agent
406 + yum install -y ruby
407 + yum install -y wget
408 + cd /home/ec2-user
409 + # you have to notice region in url
410 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
411 + chmod +x ./install
412 + ./install auto
413 + # install cloudwatch logs agent
414 + sudo yum install -y awslogs
415 + # set config file sending log to right region
416 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
417 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
418 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
419 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
420 + # start cloudwatch agent
421 + sudo systemctl start awslogsd
422 + # get node into yum
423 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
424 + # install node and npm in one line
425 + yum install -y nodejs
426 + # install pm2 to restart node app
427 + npm i -g pm2@2.4.3
428 +```
429 +* AMI 없이 인스턴스를 생성할 때 userdata를 사용
430 + * codedeploy, cloudwathch logs agent 설치
431 + * cloudwatch 설정 파일 생성
432 + * dependcies 설치(Node or Java)
433 + * pm2 설치(노드 시작/중단 사용하기 위함)
434 +
435 +```
436 +#/etc/awslogs/awscli.conf
437 +
438 +[plugins]
439 +cwlogs = cwlogs
440 +[default] ## plugin 지정
441 +region = ap-northeast-2 ## cloudwatch region 지정
442 +```
443 +
444 +```
445 +#/etc/awslogs/awslogs.conf
446 +
447 +[general] ## general 없을 시 오류 발생
448 +datetime_format = %Y-%m-%d %H:%M:%S
449 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
450 +log_stream_name = {instance_id}-codedeploy-agent-log
451 +log_group_name = codedeploy-agent-log
452 +
453 +[codedeploy-agent-logs]
454 +datetime_format = %Y-%m-%d %H:%M:%S
455 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
456 +log_stream_name = {instance_id}-codedeploy-agent-log
457 +log_group_name = codedeploy-agent-log
458 +
459 +[codedeploy-updater-logs]
460 +file = /tmp/codedeploy-agent.update.log
461 +log_stream_name = {instance_id}-codedeploy-updater-log
462 +log_group_name = codedeploy-updater-log
463 +
464 +[codedeploy-deployment-logs]
465 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
466 +log_stream_name = {instance_id}-codedeploy-deployments-log
467 +log_group_name = codedeploy-deployments-log
468 +```
469 +* applicaion 로그도 해당 형식으로 입력 시 확인 가능
470 +
471 +* ## CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
472 +```
473 +var/log/awslogs.log
474 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +![cloudformaion.png](./img/cloudformation.jpg)
4 +## 전제사항
5 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
6 +* CodeDeploy, CloudWatch Agent 설치된 AMI
7 + * AMI 없이 UserData로 설치 가능
8 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
9 + * AMI 없이 UserData로 설치 가능
10 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
11 +
12 +## 자동 배포 진행 과정
13 +
14 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
15 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
16 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
17 +
18 +# CloudFormation 인프라 구성
19 +
20 +* ### json 또는 yaml 형식으로 인프라 정의
21 + * 파라미터
22 +```yaml
23 +Parameters:
24 + KeyName:
25 + Type: String
26 + Default: dd
27 + WebappSubnets:
28 + Type: CommaDelimitedList
29 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
30 + ALBSubnets:
31 + Type: CommaDelimitedList
32 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
33 + MinSize:
34 + Type: Number
35 + Default: 2
36 + MaxSize:
37 + Type: Number
38 + Default: 3
39 + VPC:
40 + Type: String
41 + Default: vpc-aab1aac2
42 + AMIID:
43 + Type: String
44 + Default: ami-08ab3f7e72215fe91
45 + NamePrefix:
46 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
47 + Default: bluegreen
48 + Description: Prefix for resource tags made by this template (2-15 chars).
49 + MaxLength: 15
50 + MinLength: 2
51 + Type: String
52 +```
53 + * role 설정
54 + * codedeploy가 loadbalancer와 autoscaling을 이용할 수 있도록 하는 설정
55 + * Instance가 cloudwatch와 codedeploy를 이용하고 s3로부터 코드를 가져올 수 있도록 하는 설정
56 +```yaml
57 +Resources:
58 + CodeDeployRole:
59 + Type: "AWS::IAM::Role"
60 + Properties:
61 + AssumeRolePolicyDocument:
62 + Version: "2012-10-17"
63 + Statement:
64 + -
65 + Effect: "Allow"
66 + Principal:
67 + Service:
68 + - "codedeploy.amazonaws.com"
69 + Action:
70 + - "sts:AssumeRole"
71 + Policies:
72 + -
73 + PolicyName: allow-autoscaling
74 + PolicyDocument:
75 + Version: "2012-10-17"
76 + Statement:
77 + -
78 + Effect: Allow
79 + Action:
80 + - ec2:*
81 + - autoscaling:*
82 + Resource: "*"
83 + -
84 + PolicyName: allow-loadbalance
85 + PolicyDocument:
86 + Version: "2012-10-17"
87 + Statement:
88 + -
89 + Effect: Allow
90 + Action:
91 + - ec2:*
92 + - autoscaling:*
93 + Resource: "*"
94 + -
95 + Effect: Allow
96 + Action:
97 + - iam:CreateServiceLinkedRole
98 + Resource: "*"
99 + -
100 + Effect: Allow
101 + Action:
102 + - elasticloadbalancing:*
103 + Resource: "*"
104 + WebappRole:
105 + Type: "AWS::IAM::Role"
106 + Properties:
107 + AssumeRolePolicyDocument:
108 + Version: "2012-10-17"
109 + Statement:
110 + -
111 + Effect: "Allow"
112 + Principal:
113 + Service:
114 + - "ec2.amazonaws.com"
115 + - "codedeploy.amazonaws.com"
116 + - "events.amazonaws.com"
117 + Action:
118 + - "sts:AssumeRole"
119 + Policies:
120 + -
121 + PolicyName: "allow-webapp-deployment-bucket-bucket"
122 + PolicyDocument:
123 + Version: "2012-10-17"
124 + Statement:
125 + -
126 + Effect: "Allow"
127 + Action: "s3:getObject"
128 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
129 + -
130 + Effect: Allow
131 + Action:
132 + - autoscaling:*
133 + - cloudwatch:*
134 + - logs:*
135 + - sns:*
136 + Resource: "*"
137 +```
138 + * 인프라 정의
139 + * security Group
140 + * autoscaling group
141 + * loadbalancer
142 +```yaml
143 + WebappInstanceProfile:
144 + Type: "AWS::IAM::InstanceProfile"
145 + Properties:
146 + Roles:
147 + - Ref: WebappRole
148 + ALBSecurityGroup:
149 + Type: AWS::EC2::SecurityGroup
150 + Properties:
151 + GroupDescription: allow access to ALB from internet
152 + VpcId:
153 + Ref: VPC
154 + SecurityGroupIngress:
155 + - IpProtocol: tcp
156 + FromPort: '80'
157 + ToPort: '80'
158 + CidrIp: 0.0.0.0/0
159 + WebappSecurityGroup:
160 + Type: AWS::EC2::SecurityGroup
161 + Properties:
162 + GroupDescription: allow access to Webapp from ALB
163 + VpcId:
164 + Ref: VPC
165 + SecurityGroupIngress:
166 + - IpProtocol: tcp
167 + FromPort: '3000'
168 + ToPort: '3000'
169 + SourceSecurityGroupId:
170 + Ref: ALBSecurityGroup
171 + - IpProtocol: tcp
172 + FromPort: '22'
173 + ToPort: '22'
174 + CidrIp: 0.0.0.0/0
175 + WebappLaunchConfig:
176 + Type: AWS::AutoScaling::LaunchConfiguration
177 + Properties:
178 + AssociatePublicIpAddress: true
179 + ImageId:
180 + Ref: AMIID
181 + InstanceType: t2.micro
182 + KeyName:
183 + Ref: KeyName
184 + SecurityGroups:
185 + - Ref: WebappSecurityGroup
186 + IamInstanceProfile:
187 + Ref: WebappInstanceProfile
188 + UserData:
189 + Fn::Base64:
190 + !Sub |
191 + #! /bin/bash -xe
192 + # update yum just in case
193 + yum update -y
194 + # install codedeploy agent
195 + yum install -y ruby
196 + yum install -y wget
197 + cd /home/ec2-user
198 + # you have to notice region in url
199 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
200 + chmod +x ./install
201 + ./install auto
202 + # install cloudwatch logs agent
203 + sudo yum install -y awslogs
204 + # set config file sending log to right region
205 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
206 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
207 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
208 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
209 + # start cloudwatch agent
210 + sudo systemctl start awslogsd
211 + # get node into yum
212 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
213 + # install node and npm in one line
214 + yum install -y nodejs
215 + # install pm2 to restart node app
216 + npm i -g pm2@2.4.3
217 + AutoScalingGroup:
218 + Type: AWS::AutoScaling::AutoScalingGroup
219 + Properties:
220 + HealthCheckType: ELB
221 + HealthCheckGracePeriod: 300
222 + MinSize:
223 + Ref: MinSize
224 + MaxSize:
225 + Ref: MaxSize
226 + LaunchConfigurationName:
227 + Ref: WebappLaunchConfig
228 + VPCZoneIdentifier:
229 + Ref: WebappSubnets
230 + TargetGroupARNs:
231 + - Ref: ALBTargetGroup
232 + Tags:
233 + - Key: Name
234 + Value: webapp-example
235 + PropagateAtLaunch: true
236 + ALBListener:
237 + Type: AWS::ElasticLoadBalancingV2::Listener
238 + Properties:
239 + DefaultActions:
240 + -
241 + Type: forward
242 + TargetGroupArn:
243 + Ref: ALBTargetGroup
244 + LoadBalancerArn:
245 + Ref: LoadBalancer
246 + Port: 80
247 + Protocol: HTTP
248 + LoadBalancer:
249 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
250 + Properties:
251 + Name: testLoadbalancer
252 + Scheme: internet-facing
253 + Subnets:
254 + Ref: ALBSubnets
255 + SecurityGroups:
256 + - Ref: ALBSecurityGroup
257 + Tags:
258 + - Key: Name
259 + Value:
260 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
261 + ALBTargetGroup:
262 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
263 + Properties:
264 + TargetGroupAttributes:
265 + - Key: deregistration_delay.timeout_seconds
266 + Value: 30
267 + HealthCheckIntervalSeconds: 30
268 + UnhealthyThresholdCount: 2
269 + HealthyThresholdCount: 2
270 + HealthCheckPath: /
271 + Port: 3000
272 + Protocol: HTTP
273 + VpcId:
274 + Ref: VPC
275 +```
276 + * codedeploy 설정
277 + * codedeploy application을 설정
278 + * codedeploy group을 이용하여 세부 배포 설정
279 +```yaml
280 + WebappApplication:
281 + Type: "AWS::CodeDeploy::Application"
282 + Properties:
283 + ApplicationName: testApp
284 + WebappDeploymentGroup:
285 + Type: "AWS::CodeDeploy::DeploymentGroup"
286 + Properties:
287 + DeploymentGroupName: test-group
288 + ApplicationName: !Ref WebappApplication
289 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
290 + DeploymentConfigName: CodeDeployDefault.OneAtATime
291 + DeploymentStyle:
292 + DeploymentType: IN_PLACE
293 + DeploymentOption: WITH_TRAFFIC_CONTROL
294 + LoadBalancerInfo:
295 + TargetGroupInfoList:
296 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
297 + AutoScalingGroups:
298 + - Ref: AutoScalingGroup
299 + WebappDeploymentBucket:
300 + Type: "AWS::S3::Bucket"
301 + Properties:
302 + BucketName: 'testtest11324'
303 +```
304 +* output 설정
305 + * loadbalancer dns와 같이 인프라 생성이후에 정의되는 변수들을 출력하여 굳이 콘솔에서 로드밸런서 주소를 확인하지 않아도 된다
306 +```yaml
307 +Outputs:
308 + WebappUrl:
309 + Description: Webapp URL
310 + Value: !GetAtt LoadBalancer.DNSName
311 + DeploymentGroup:
312 + Description: Webapp Deployment Group
313 + Value: !Ref WebappDeploymentGroup
314 + DeploymentBucket:
315 + Description: Deployment bucket
316 + Value: !Ref WebappDeploymentBucket
317 + ApplicationName:
318 + Description: CodeDeploy Application name
319 + Value: !Ref WebappApplication
320 +```
321 +* ### Cloudformation 스택 생성
322 +```
323 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
324 +```
325 +* ### Cloudformation 스택 업데이트
326 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
327 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
328 +```
329 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
330 +```
331 +* ### Cloudformation 스택 삭제
332 +```
333 +$ aws cloudformation delete-stack --stack-name test-template-1
334 +```
335 +
336 +# 빌드 파일 S3 전송
337 +```
338 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
339 +```
340 +
341 +# 빌드된 파일 배포
342 +
343 +## 배포 방식 종류
344 +* ### In Place 방식
345 + * 기존에 존재하는 인스턴스에 배포하는 방식
346 +* ### Blue / Green 방식
347 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
348 +
349 +## LoadBalancer로 트래픽 분배
350 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
351 +
352 +## appspec.yml 설정
353 +```
354 +version: 0.0
355 +os: linux
356 +files:
357 + - source: src
358 + destination: /opt/webapp
359 + - source: node_modules
360 + destination: /opt/webapp/node_modules
361 +hooks:
362 + ApplicationStop:
363 + - location: deployment_scripts/stop.sh
364 + timeout: 180
365 + AfterInstall:
366 + - location: deployment_scripts/deploy.sh
367 + timeout: 180
368 + ApplicationStart:
369 + - location: deployment_scripts/start.sh
370 + timeout: 180
371 +
372 +```
373 +* ### start.sh
374 +```
375 +#!/usr/bin/env bash
376 +
377 +sudo pm2 stop node-app
378 +# actually start the server
379 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
380 +```
381 +* ### stop.sh
382 +```
383 +#!/usr/bin/env bash
384 +
385 +sudo pm2 stop node-app
386 +sleep 10
387 +```
388 +
389 +
390 +## 명령어
391 +```
392 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
393 +```
394 +
395 +# 배포 관련 로그 확인
396 +
397 +## CloudWatch Logs 관련 설정 파일
398 +* UserData 설정
399 +```yaml
400 +UserData:
401 + Fn::Base64:
402 + !Sub |
403 + #! /bin/bash -xe
404 + # update yum just in case
405 + yum update -y
406 + # install codedeploy agent
407 + yum install -y ruby
408 + yum install -y wget
409 + cd /home/ec2-user
410 + # you have to notice region in url
411 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
412 + chmod +x ./install
413 + ./install auto
414 + # install cloudwatch logs agent
415 + sudo yum install -y awslogs
416 + # set config file sending log to right region
417 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
418 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
419 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
420 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
421 + # start cloudwatch agent
422 + sudo systemctl start awslogsd
423 + # get node into yum
424 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
425 + # install node and npm in one line
426 + yum install -y nodejs
427 + # install pm2 to restart node app
428 + npm i -g pm2@2.4.3
429 +```
430 +* AMI 없이 인스턴스를 생성할 때 userdata를 사용
431 + * codedeploy, cloudwathch logs agent 설치
432 + * cloudwatch 설정 파일 생성
433 + * dependcies 설치(Node or Java)
434 + * pm2 설치(노드 시작/중단 사용하기 위함)
435 +
436 +```
437 +#/etc/awslogs/awscli.conf
438 +
439 +[plugins]
440 +cwlogs = cwlogs
441 +[default] ## plugin 지정
442 +region = ap-northeast-2 ## cloudwatch region 지정
443 +```
444 +
445 +```
446 +#/etc/awslogs/awslogs.conf
447 +
448 +[general] ## general 없을 시 오류 발생
449 +datetime_format = %Y-%m-%d %H:%M:%S
450 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
451 +log_stream_name = {instance_id}-codedeploy-agent-log
452 +log_group_name = codedeploy-agent-log
453 +
454 +[codedeploy-agent-logs]
455 +datetime_format = %Y-%m-%d %H:%M:%S
456 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
457 +log_stream_name = {instance_id}-codedeploy-agent-log
458 +log_group_name = codedeploy-agent-log
459 +
460 +[codedeploy-updater-logs]
461 +file = /tmp/codedeploy-agent.update.log
462 +log_stream_name = {instance_id}-codedeploy-updater-log
463 +log_group_name = codedeploy-updater-log
464 +
465 +[codedeploy-deployment-logs]
466 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
467 +log_stream_name = {instance_id}-codedeploy-deployments-log
468 +log_group_name = codedeploy-deployments-log
469 +```
470 +* applicaion 로그도 해당 형식으로 입력 시 확인 가능
471 +
472 +* ## CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
473 +```
474 +var/log/awslogs.log
475 +```
...\ No newline at end of file ...\ No newline at end of file
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +![cloudformaion.png](./img/cloudformation.png)
4 +## 전제사항
5 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
6 +* CodeDeploy, CloudWatch Agent 설치된 AMI
7 + * AMI 없이 UserData로 설치 가능
8 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
9 + * AMI 없이 UserData로 설치 가능
10 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
11 +
12 +## 자동 배포 진행 과정
13 +
14 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
15 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
16 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
17 +
18 +# CloudFormation 인프라 구성
19 +
20 +* ### json 또는 yaml 형식으로 인프라 정의
21 + * 파라미터
22 +```yaml
23 +Parameters:
24 + KeyName:
25 + Type: String
26 + Default: dd
27 + WebappSubnets:
28 + Type: CommaDelimitedList
29 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
30 + ALBSubnets:
31 + Type: CommaDelimitedList
32 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
33 + MinSize:
34 + Type: Number
35 + Default: 2
36 + MaxSize:
37 + Type: Number
38 + Default: 3
39 + VPC:
40 + Type: String
41 + Default: vpc-aab1aac2
42 + AMIID:
43 + Type: String
44 + Default: ami-08ab3f7e72215fe91
45 + NamePrefix:
46 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
47 + Default: bluegreen
48 + Description: Prefix for resource tags made by this template (2-15 chars).
49 + MaxLength: 15
50 + MinLength: 2
51 + Type: String
52 +```
53 + * role 설정
54 + * codedeploy가 loadbalancer와 autoscaling을 이용할 수 있도록 하는 설정
55 + * Instance가 cloudwatch와 codedeploy를 이용하고 s3로부터 코드를 가져올 수 있도록 하는 설정
56 +```yaml
57 +Resources:
58 + CodeDeployRole:
59 + Type: "AWS::IAM::Role"
60 + Properties:
61 + AssumeRolePolicyDocument:
62 + Version: "2012-10-17"
63 + Statement:
64 + -
65 + Effect: "Allow"
66 + Principal:
67 + Service:
68 + - "codedeploy.amazonaws.com"
69 + Action:
70 + - "sts:AssumeRole"
71 + Policies:
72 + -
73 + PolicyName: allow-autoscaling
74 + PolicyDocument:
75 + Version: "2012-10-17"
76 + Statement:
77 + -
78 + Effect: Allow
79 + Action:
80 + - ec2:*
81 + - autoscaling:*
82 + Resource: "*"
83 + -
84 + PolicyName: allow-loadbalance
85 + PolicyDocument:
86 + Version: "2012-10-17"
87 + Statement:
88 + -
89 + Effect: Allow
90 + Action:
91 + - ec2:*
92 + - autoscaling:*
93 + Resource: "*"
94 + -
95 + Effect: Allow
96 + Action:
97 + - iam:CreateServiceLinkedRole
98 + Resource: "*"
99 + -
100 + Effect: Allow
101 + Action:
102 + - elasticloadbalancing:*
103 + Resource: "*"
104 + WebappRole:
105 + Type: "AWS::IAM::Role"
106 + Properties:
107 + AssumeRolePolicyDocument:
108 + Version: "2012-10-17"
109 + Statement:
110 + -
111 + Effect: "Allow"
112 + Principal:
113 + Service:
114 + - "ec2.amazonaws.com"
115 + - "codedeploy.amazonaws.com"
116 + - "events.amazonaws.com"
117 + Action:
118 + - "sts:AssumeRole"
119 + Policies:
120 + -
121 + PolicyName: "allow-webapp-deployment-bucket-bucket"
122 + PolicyDocument:
123 + Version: "2012-10-17"
124 + Statement:
125 + -
126 + Effect: "Allow"
127 + Action: "s3:getObject"
128 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
129 + -
130 + Effect: Allow
131 + Action:
132 + - autoscaling:*
133 + - cloudwatch:*
134 + - logs:*
135 + - sns:*
136 + Resource: "*"
137 +```
138 + * 인프라 정의
139 + * security Group
140 + * autoscaling group
141 + * loadbalancer
142 +```yaml
143 + WebappInstanceProfile:
144 + Type: "AWS::IAM::InstanceProfile"
145 + Properties:
146 + Roles:
147 + - Ref: WebappRole
148 + ALBSecurityGroup:
149 + Type: AWS::EC2::SecurityGroup
150 + Properties:
151 + GroupDescription: allow access to ALB from internet
152 + VpcId:
153 + Ref: VPC
154 + SecurityGroupIngress:
155 + - IpProtocol: tcp
156 + FromPort: '80'
157 + ToPort: '80'
158 + CidrIp: 0.0.0.0/0
159 + WebappSecurityGroup:
160 + Type: AWS::EC2::SecurityGroup
161 + Properties:
162 + GroupDescription: allow access to Webapp from ALB
163 + VpcId:
164 + Ref: VPC
165 + SecurityGroupIngress:
166 + - IpProtocol: tcp
167 + FromPort: '3000'
168 + ToPort: '3000'
169 + SourceSecurityGroupId:
170 + Ref: ALBSecurityGroup
171 + - IpProtocol: tcp
172 + FromPort: '22'
173 + ToPort: '22'
174 + CidrIp: 0.0.0.0/0
175 + WebappLaunchConfig:
176 + Type: AWS::AutoScaling::LaunchConfiguration
177 + Properties:
178 + AssociatePublicIpAddress: true
179 + ImageId:
180 + Ref: AMIID
181 + InstanceType: t2.micro
182 + KeyName:
183 + Ref: KeyName
184 + SecurityGroups:
185 + - Ref: WebappSecurityGroup
186 + IamInstanceProfile:
187 + Ref: WebappInstanceProfile
188 + UserData:
189 + Fn::Base64:
190 + !Sub |
191 + #! /bin/bash -xe
192 + # update yum just in case
193 + yum update -y
194 + # install codedeploy agent
195 + yum install -y ruby
196 + yum install -y wget
197 + cd /home/ec2-user
198 + # you have to notice region in url
199 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
200 + chmod +x ./install
201 + ./install auto
202 + # install cloudwatch logs agent
203 + sudo yum install -y awslogs
204 + # set config file sending log to right region
205 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
206 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
207 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
208 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
209 + # start cloudwatch agent
210 + sudo systemctl start awslogsd
211 + # get node into yum
212 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
213 + # install node and npm in one line
214 + yum install -y nodejs
215 + # install pm2 to restart node app
216 + npm i -g pm2@2.4.3
217 + AutoScalingGroup:
218 + Type: AWS::AutoScaling::AutoScalingGroup
219 + Properties:
220 + HealthCheckType: ELB
221 + HealthCheckGracePeriod: 300
222 + MinSize:
223 + Ref: MinSize
224 + MaxSize:
225 + Ref: MaxSize
226 + LaunchConfigurationName:
227 + Ref: WebappLaunchConfig
228 + VPCZoneIdentifier:
229 + Ref: WebappSubnets
230 + TargetGroupARNs:
231 + - Ref: ALBTargetGroup
232 + Tags:
233 + - Key: Name
234 + Value: webapp-example
235 + PropagateAtLaunch: true
236 + ALBListener:
237 + Type: AWS::ElasticLoadBalancingV2::Listener
238 + Properties:
239 + DefaultActions:
240 + -
241 + Type: forward
242 + TargetGroupArn:
243 + Ref: ALBTargetGroup
244 + LoadBalancerArn:
245 + Ref: LoadBalancer
246 + Port: 80
247 + Protocol: HTTP
248 + LoadBalancer:
249 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
250 + Properties:
251 + Name: testLoadbalancer
252 + Scheme: internet-facing
253 + Subnets:
254 + Ref: ALBSubnets
255 + SecurityGroups:
256 + - Ref: ALBSecurityGroup
257 + Tags:
258 + - Key: Name
259 + Value:
260 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
261 + ALBTargetGroup:
262 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
263 + Properties:
264 + TargetGroupAttributes:
265 + - Key: deregistration_delay.timeout_seconds
266 + Value: 30
267 + HealthCheckIntervalSeconds: 30
268 + UnhealthyThresholdCount: 2
269 + HealthyThresholdCount: 2
270 + HealthCheckPath: /
271 + Port: 3000
272 + Protocol: HTTP
273 + VpcId:
274 + Ref: VPC
275 +```
276 + * codedeploy 설정
277 + * codedeploy application을 설정
278 + * codedeploy group을 이용하여 세부 배포 설정
279 +```yaml
280 + WebappApplication:
281 + Type: "AWS::CodeDeploy::Application"
282 + Properties:
283 + ApplicationName: testApp
284 + WebappDeploymentGroup:
285 + Type: "AWS::CodeDeploy::DeploymentGroup"
286 + Properties:
287 + DeploymentGroupName: test-group
288 + ApplicationName: !Ref WebappApplication
289 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
290 + DeploymentConfigName: CodeDeployDefault.OneAtATime
291 + DeploymentStyle:
292 + DeploymentType: IN_PLACE
293 + DeploymentOption: WITH_TRAFFIC_CONTROL
294 + LoadBalancerInfo:
295 + TargetGroupInfoList:
296 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
297 + AutoScalingGroups:
298 + - Ref: AutoScalingGroup
299 + WebappDeploymentBucket:
300 + Type: "AWS::S3::Bucket"
301 + Properties:
302 + BucketName: 'testtest11324'
303 +```
304 +* output 설정
305 + * loadbalancer dns와 같이 인프라 생성이후에 정의되는 변수들을 출력하여 굳이 콘솔에서 로드밸런서 주소를 확인하지 않아도 된다
306 +```yaml
307 +Outputs:
308 + WebappUrl:
309 + Description: Webapp URL
310 + Value: !GetAtt LoadBalancer.DNSName
311 + DeploymentGroup:
312 + Description: Webapp Deployment Group
313 + Value: !Ref WebappDeploymentGroup
314 + DeploymentBucket:
315 + Description: Deployment bucket
316 + Value: !Ref WebappDeploymentBucket
317 + ApplicationName:
318 + Description: CodeDeploy Application name
319 + Value: !Ref WebappApplication
320 +```
321 +* ### Cloudformation 스택 생성
322 +```
323 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
324 +```
325 +* ### Cloudformation 스택 업데이트
326 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
327 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
328 +```
329 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
330 +```
331 +* ### Cloudformation 스택 삭제
332 +```
333 +$ aws cloudformation delete-stack --stack-name test-template-1
334 +```
335 +
336 +# 빌드 파일 S3 전송
337 +```
338 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
339 +```
340 +
341 +# 빌드된 파일 배포
342 +
343 +## 배포 방식 종류
344 +* ### In Place 방식
345 + * 기존에 존재하는 인스턴스에 배포하는 방식
346 +* ### Blue / Green 방식
347 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
348 +
349 +## LoadBalancer로 트래픽 분배
350 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
351 +
352 +## appspec.yml 설정
353 +```
354 +version: 0.0
355 +os: linux
356 +files:
357 + - source: src
358 + destination: /opt/webapp
359 + - source: node_modules
360 + destination: /opt/webapp/node_modules
361 +hooks:
362 + ApplicationStop:
363 + - location: deployment_scripts/stop.sh
364 + timeout: 180
365 + AfterInstall:
366 + - location: deployment_scripts/deploy.sh
367 + timeout: 180
368 + ApplicationStart:
369 + - location: deployment_scripts/start.sh
370 + timeout: 180
371 +
372 +```
373 +* ### start.sh
374 +```
375 +#!/usr/bin/env bash
376 +
377 +sudo pm2 stop node-app
378 +# actually start the server
379 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
380 +```
381 +* ### stop.sh
382 +```
383 +#!/usr/bin/env bash
384 +
385 +sudo pm2 stop node-app
386 +sleep 10
387 +```
388 +
389 +
390 +## 명령어
391 +```
392 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
393 +```
394 +
395 +# 배포 관련 로그 확인
396 +
397 +## CloudWatch Logs 관련 설정 파일
398 +* UserData 설정
399 +```yaml
400 +UserData:
401 + Fn::Base64:
402 + !Sub |
403 + #! /bin/bash -xe
404 + # update yum just in case
405 + yum update -y
406 + # install codedeploy agent
407 + yum install -y ruby
408 + yum install -y wget
409 + cd /home/ec2-user
410 + # you have to notice region in url
411 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
412 + chmod +x ./install
413 + ./install auto
414 + # install cloudwatch logs agent
415 + sudo yum install -y awslogs
416 + # set config file sending log to right region
417 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
418 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
419 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
420 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
421 + # start cloudwatch agent
422 + sudo systemctl start awslogsd
423 + # get node into yum
424 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
425 + # install node and npm in one line
426 + yum install -y nodejs
427 + # install pm2 to restart node app
428 + npm i -g pm2@2.4.3
429 +```
430 +* AMI 없이 인스턴스를 생성할 때 userdata를 사용
431 + * codedeploy, cloudwathch logs agent 설치
432 + * cloudwatch 설정 파일 생성
433 + * dependcies 설치(Node or Java)
434 + * pm2 설치(노드 시작/중단 사용하기 위함)
435 +
436 +```
437 +#/etc/awslogs/awscli.conf
438 +
439 +[plugins]
440 +cwlogs = cwlogs
441 +[default] ## plugin 지정
442 +region = ap-northeast-2 ## cloudwatch region 지정
443 +```
444 +
445 +```
446 +#/etc/awslogs/awslogs.conf
447 +
448 +[general] ## general 없을 시 오류 발생
449 +datetime_format = %Y-%m-%d %H:%M:%S
450 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
451 +log_stream_name = {instance_id}-codedeploy-agent-log
452 +log_group_name = codedeploy-agent-log
453 +
454 +[codedeploy-agent-logs]
455 +datetime_format = %Y-%m-%d %H:%M:%S
456 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
457 +log_stream_name = {instance_id}-codedeploy-agent-log
458 +log_group_name = codedeploy-agent-log
459 +
460 +[codedeploy-updater-logs]
461 +file = /tmp/codedeploy-agent.update.log
462 +log_stream_name = {instance_id}-codedeploy-updater-log
463 +log_group_name = codedeploy-updater-log
464 +
465 +[codedeploy-deployment-logs]
466 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
467 +log_stream_name = {instance_id}-codedeploy-deployments-log
468 +log_group_name = codedeploy-deployments-log
469 +```
470 +* applicaion 로그도 해당 형식으로 입력 시 확인 가능
471 +
472 +* ## CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
473 +```
474 +var/log/awslogs.log
475 +```
...\ No newline at end of file ...\ No newline at end of file
1 +[plugins]
2 +cwlogs = cwlogs
3 +[default]
4 +region = ap-northeast-2
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + - autoscaling:*
115 + Resource: "*"
116 + -
117 + Effect: Allow
118 + Action:
119 + - ec2:*
120 + - autoscaling:*
121 + Resource: "*"
122 + WebappRole:
123 + Type: "AWS::IAM::Role"
124 + Properties:
125 + AssumeRolePolicyDocument:
126 + Version: "2012-10-17"
127 + Statement:
128 + -
129 + Effect: "Allow"
130 + Principal:
131 + Service:
132 + - "ec2.amazonaws.com"
133 + - "codedeploy.amazonaws.com"
134 + Action:
135 + - "sts:AssumeRole"
136 + Policies:
137 + -
138 + PolicyName: "allow-webapp-deployment-bucket-bucket"
139 + PolicyDocument:
140 + Version: "2012-10-17"
141 + Statement:
142 + -
143 + Effect: "Allow"
144 + Action: "s3:getObject"
145 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
146 + WebappInstanceProfile:
147 + Type: "AWS::IAM::InstanceProfile"
148 + Properties:
149 + Roles:
150 + - Ref: WebappRole
151 + WebappLaunchConfig:
152 + Type: AWS::AutoScaling::LaunchConfiguration
153 + Properties:
154 + AssociatePublicIpAddress: true
155 + ImageId:
156 + Ref: AMIID
157 + InstanceType: t2.micro
158 + KeyName:
159 + Ref: KeyName
160 + SecurityGroups:
161 + - Ref: WebappSecurityGroup
162 + IamInstanceProfile:
163 + Ref: WebappInstanceProfile
164 + UserData:
165 + Fn::Base64: !Sub |
166 + #! /bin/bash -xe
167 + # update yum just in case
168 + yum update -y
169 + # get node into yum
170 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
171 + # install node and npm in one line
172 + yum install -y nodejs
173 + install pm2 to restart node app
174 + npm i -g pm2@2.4.3
175 + AutoScalingGroup:
176 + Type: AWS::AutoScaling::AutoScalingGroup
177 + Properties:
178 + HealthCheckType: ELB
179 + HealthCheckGracePeriod: 300
180 + MinSize:
181 + Ref: MinSize
182 + MaxSize:
183 + Ref: MaxSize
184 + LaunchConfigurationName:
185 + Ref: WebappLaunchConfig
186 + VPCZoneIdentifier:
187 + Ref: WebappSubnets
188 + TargetGroupARNs:
189 + - Ref: ALBTargetGroup
190 + Tags:
191 + - Key: Name
192 + Value: webapp-example
193 + PropagateAtLaunch: true
194 + ALBListener:
195 + Type: AWS::ElasticLoadBalancingV2::Listener
196 + Properties:
197 + DefaultActions:
198 + -
199 + Type: forward
200 + TargetGroupArn:
201 + Ref: ALBTargetGroup
202 + LoadBalancerArn:
203 + Ref: ApplicationLoadBalancer
204 + Port: 80
205 + Protocol: HTTP
206 + ApplicationLoadBalancer:
207 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
208 + Properties:
209 + Name: testLoadbalancer
210 + Scheme: internet-facing
211 + Subnets:
212 + Ref: ALBSubnets
213 + SecurityGroups:
214 + - Ref: ALBSecurityGroup
215 + ALBTargetGroup:
216 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
217 + Properties:
218 + HealthCheckIntervalSeconds: 30
219 + UnhealthyThresholdCount: 2
220 + HealthyThresholdCount: 2
221 + HealthCheckPath: /
222 + Port: 3000
223 + Protocol: HTTP
224 + VpcId:
225 + Ref: VPC
226 +Outputs:
227 + WebappUrl:
228 + Description: Webapp URL
229 + Value: !GetAtt ApplicationLoadBalancer.DNSName
230 + DeploymentGroup:
231 + Description: Webapp Deployment Group
232 + Value: !Ref WebappDeploymentGroup
233 + DeploymentBucket:
234 + Description: Deployment bucket
235 + Value: !Ref WebappDeploymentBucket
236 + ApplicationName:
237 + Description: CodeDeploy Application name
238 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + - autoscaling:*
115 + Resource: "*"
116 + -
117 + Effect: Allow
118 + Action:
119 + - elasticloadbalancing:*
120 + Resource: "*"
121 + WebappRole:
122 + Type: "AWS::IAM::Role"
123 + Properties:
124 + AssumeRolePolicyDocument:
125 + Version: "2012-10-17"
126 + Statement:
127 + -
128 + Effect: "Allow"
129 + Principal:
130 + Service:
131 + - "ec2.amazonaws.com"
132 + - "codedeploy.amazonaws.com"
133 + Action:
134 + - "sts:AssumeRole"
135 + Policies:
136 + -
137 + PolicyName: "allow-webapp-deployment-bucket-bucket"
138 + PolicyDocument:
139 + Version: "2012-10-17"
140 + Statement:
141 + -
142 + Effect: "Allow"
143 + Action: "s3:getObject"
144 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
145 + WebappInstanceProfile:
146 + Type: "AWS::IAM::InstanceProfile"
147 + Properties:
148 + Roles:
149 + - Ref: WebappRole
150 + WebappLaunchConfig:
151 + Type: AWS::AutoScaling::LaunchConfiguration
152 + Properties:
153 + AssociatePublicIpAddress: true
154 + ImageId:
155 + Ref: AMIID
156 + InstanceType: t2.micro
157 + KeyName:
158 + Ref: KeyName
159 + SecurityGroups:
160 + - Ref: WebappSecurityGroup
161 + IamInstanceProfile:
162 + Ref: WebappInstanceProfile
163 + UserData:
164 + Fn::Base64: !Sub |
165 + #! /bin/bash -xe
166 + # update yum just in case
167 + yum update -y
168 + # get node into yum
169 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
170 + # install node and npm in one line
171 + yum install -y nodejs
172 + install pm2 to restart node app
173 + npm i -g pm2@2.4.3
174 + AutoScalingGroup:
175 + Type: AWS::AutoScaling::AutoScalingGroup
176 + Properties:
177 + HealthCheckType: ELB
178 + HealthCheckGracePeriod: 300
179 + MinSize:
180 + Ref: MinSize
181 + MaxSize:
182 + Ref: MaxSize
183 + LaunchConfigurationName:
184 + Ref: WebappLaunchConfig
185 + VPCZoneIdentifier:
186 + Ref: WebappSubnets
187 + TargetGroupARNs:
188 + - Ref: ALBTargetGroup
189 + Tags:
190 + - Key: Name
191 + Value: webapp-example
192 + PropagateAtLaunch: true
193 + ALBListener:
194 + Type: AWS::ElasticLoadBalancingV2::Listener
195 + Properties:
196 + DefaultActions:
197 + -
198 + Type: forward
199 + TargetGroupArn:
200 + Ref: ALBTargetGroup
201 + LoadBalancerArn:
202 + Ref: ApplicationLoadBalancer
203 + Port: 80
204 + Protocol: HTTP
205 + ApplicationLoadBalancer:
206 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
207 + Properties:
208 + Name: testLoadbalancer
209 + Scheme: internet-facing
210 + Subnets:
211 + Ref: ALBSubnets
212 + SecurityGroups:
213 + - Ref: ALBSecurityGroup
214 + ALBTargetGroup:
215 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
216 + Properties:
217 + HealthCheckIntervalSeconds: 30
218 + UnhealthyThresholdCount: 2
219 + HealthyThresholdCount: 2
220 + HealthCheckPath: /
221 + Port: 3000
222 + Protocol: HTTP
223 + VpcId:
224 + Ref: VPC
225 +Outputs:
226 + WebappUrl:
227 + Description: Webapp URL
228 + Value: !GetAtt ApplicationLoadBalancer.DNSName
229 + DeploymentGroup:
230 + Description: Webapp Deployment Group
231 + Value: !Ref WebappDeploymentGroup
232 + DeploymentBucket:
233 + Description: Deployment bucket
234 + Value: !Ref WebappDeploymentBucket
235 + ApplicationName:
236 + Description: CodeDeploy Application name
237 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !Ref ApplicationLoadBalancer:
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !Ref ApplicationLoadBalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !Ref ApplicationLoadBalancer.name
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !GetAtt ApplicationLoadBalancer.name
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: LoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + LoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt LoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !Ref LoadBalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: LoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + LoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt LoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: ApplicationLoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + ApplicationLoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt ApplicationLoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: !Ref LoadBalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: LoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + LoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt LoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 +Resources:
24 + WebappApplication:
25 + Type: "AWS::CodeDeploy::Application"
26 + Properties:
27 + ApplicationName: testApp
28 + WebappDeploymentGroup:
29 + Type: "AWS::CodeDeploy::DeploymentGroup"
30 + Properties:
31 + DeploymentGroupName: test-group
32 + ApplicationName: !Ref WebappApplication
33 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
34 + DeploymentConfigName: CodeDeployDefault.OneAtATime
35 + DeploymentStyle:
36 + DeploymentType: IN_PLACE
37 + DeploymentOption: WITH_TRAFFIC_CONTROL
38 + LoadBalancerInfo:
39 + ElbInfoList:
40 + - Name: testLoadbalancer
41 + AutoScalingGroups:
42 + - Ref: AutoScalingGroup
43 + ALBSecurityGroup:
44 + Type: AWS::EC2::SecurityGroup
45 + Properties:
46 + GroupDescription: allow access to ALB from internet
47 + VpcId:
48 + Ref: VPC
49 + SecurityGroupIngress:
50 + - IpProtocol: tcp
51 + FromPort: '80'
52 + ToPort: '80'
53 + CidrIp: 0.0.0.0/0
54 + WebappSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to Webapp from ALB
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '3000'
63 + ToPort: '3000'
64 + SourceSecurityGroupId:
65 + Ref: ALBSecurityGroup
66 + - IpProtocol: tcp
67 + FromPort: '22'
68 + ToPort: '22'
69 + CidrIp: 0.0.0.0/0
70 + WebappDeploymentBucket:
71 + Type: "AWS::S3::Bucket"
72 + Properties:
73 + BucketName: 'testtest11324'
74 + CodeDeployRole:
75 + Type: "AWS::IAM::Role"
76 + Properties:
77 + AssumeRolePolicyDocument:
78 + Version: "2012-10-17"
79 + Statement:
80 + -
81 + Effect: "Allow"
82 + Principal:
83 + Service:
84 + - "codedeploy.amazonaws.com"
85 + Action:
86 + - "sts:AssumeRole"
87 + Policies:
88 + -
89 + PolicyName: allow-autoscaling
90 + PolicyDocument:
91 + Version: "2012-10-17"
92 + Statement:
93 + -
94 + Effect: Allow
95 + Action:
96 + - ec2:*
97 + - autoscaling:*
98 + Resource: "*"
99 + -
100 + PolicyName: allow-loadbalance
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + Effect: Allow
112 + Action:
113 + - iam:CreateServiceLinkedRole
114 + Resource: "*"
115 + -
116 + Effect: Allow
117 + Action:
118 + - elasticloadbalancing:*
119 + Resource: "*"
120 + WebappRole:
121 + Type: "AWS::IAM::Role"
122 + Properties:
123 + AssumeRolePolicyDocument:
124 + Version: "2012-10-17"
125 + Statement:
126 + -
127 + Effect: "Allow"
128 + Principal:
129 + Service:
130 + - "ec2.amazonaws.com"
131 + - "codedeploy.amazonaws.com"
132 + Action:
133 + - "sts:AssumeRole"
134 + Policies:
135 + -
136 + PolicyName: "allow-webapp-deployment-bucket-bucket"
137 + PolicyDocument:
138 + Version: "2012-10-17"
139 + Statement:
140 + -
141 + Effect: "Allow"
142 + Action: "s3:getObject"
143 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
144 + WebappInstanceProfile:
145 + Type: "AWS::IAM::InstanceProfile"
146 + Properties:
147 + Roles:
148 + - Ref: WebappRole
149 + WebappLaunchConfig:
150 + Type: AWS::AutoScaling::LaunchConfiguration
151 + Properties:
152 + AssociatePublicIpAddress: true
153 + ImageId:
154 + Ref: AMIID
155 + InstanceType: t2.micro
156 + KeyName:
157 + Ref: KeyName
158 + SecurityGroups:
159 + - Ref: WebappSecurityGroup
160 + IamInstanceProfile:
161 + Ref: WebappInstanceProfile
162 + UserData:
163 + Fn::Base64: !Sub |
164 + #! /bin/bash -xe
165 + # update yum just in case
166 + yum update -y
167 + # get node into yum
168 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
169 + # install node and npm in one line
170 + yum install -y nodejs
171 + install pm2 to restart node app
172 + npm i -g pm2@2.4.3
173 + AutoScalingGroup:
174 + Type: AWS::AutoScaling::AutoScalingGroup
175 + Properties:
176 + HealthCheckType: ELB
177 + HealthCheckGracePeriod: 300
178 + MinSize:
179 + Ref: MinSize
180 + MaxSize:
181 + Ref: MaxSize
182 + LaunchConfigurationName:
183 + Ref: WebappLaunchConfig
184 + VPCZoneIdentifier:
185 + Ref: WebappSubnets
186 + TargetGroupARNs:
187 + - Ref: ALBTargetGroup
188 + Tags:
189 + - Key: Name
190 + Value: webapp-example
191 + PropagateAtLaunch: true
192 + ALBListener:
193 + Type: AWS::ElasticLoadBalancingV2::Listener
194 + Properties:
195 + DefaultActions:
196 + -
197 + Type: forward
198 + TargetGroupArn:
199 + Ref: ALBTargetGroup
200 + LoadBalancerArn:
201 + Ref: LoadBalancer
202 + Port: 80
203 + Protocol: HTTP
204 + LoadBalancer:
205 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
206 + Properties:
207 + Name: testLoadbalancer
208 + Scheme: internet-facing
209 + Subnets:
210 + Ref: ALBSubnets
211 + SecurityGroups:
212 + - Ref: ALBSecurityGroup
213 + ALBTargetGroup:
214 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
215 + Properties:
216 + HealthCheckIntervalSeconds: 30
217 + UnhealthyThresholdCount: 2
218 + HealthyThresholdCount: 2
219 + HealthCheckPath: /
220 + Port: 3000
221 + Protocol: HTTP
222 + VpcId:
223 + Ref: VPC
224 +Outputs:
225 + WebappUrl:
226 + Description: Webapp URL
227 + Value: !GetAtt LoadBalancer.DNSName
228 + DeploymentGroup:
229 + Description: Webapp Deployment Group
230 + Value: !Ref WebappDeploymentGroup
231 + DeploymentBucket:
232 + Description: Deployment bucket
233 + Value: !Ref WebappDeploymentBucket
234 + ApplicationName:
235 + Description: CodeDeploy Application name
236 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + ElbInfoList:
47 + - Name: testLoadbalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + ALBTargetGroup:
221 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
222 + Properties:
223 + HealthCheckIntervalSeconds: 30
224 + UnhealthyThresholdCount: 2
225 + HealthyThresholdCount: 2
226 + HealthCheckPath: /
227 + Port: 3000
228 + Protocol: HTTP
229 + VpcId:
230 + Ref: VPC
231 +Outputs:
232 + WebappUrl:
233 + Description: Webapp URL
234 + Value: !GetAtt LoadBalancer.DNSName
235 + DeploymentGroup:
236 + Description: Webapp Deployment Group
237 + Value: !Ref WebappDeploymentGroup
238 + DeploymentBucket:
239 + Description: Deployment bucket
240 + Value: !Ref WebappDeploymentBucket
241 + ApplicationName:
242 + Description: CodeDeploy Application name
243 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + ElbInfoList:
47 + - Name: testLoadbalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + ElbInfoList:
47 + - Name: testLoadbalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList::
47 + - Name: testLoadbalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: testLoadbalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !Ref LoadBalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Scheme: internet-facing
215 + Subnets:
216 + Ref: ALBSubnets
217 + SecurityGroups:
218 + - Ref: ALBSecurityGroup
219 + Tags:
220 + - Key: Name
221 + Value:
222 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
223 + ALBTargetGroup:
224 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
225 + Properties:
226 + HealthCheckIntervalSeconds: 30
227 + UnhealthyThresholdCount: 2
228 + HealthyThresholdCount: 2
229 + HealthCheckPath: /
230 + Port: 3000
231 + Protocol: HTTP
232 + VpcId:
233 + Ref: VPC
234 +Outputs:
235 + WebappUrl:
236 + Description: Webapp URL
237 + Value: !GetAtt LoadBalancer.DNSName
238 + DeploymentGroup:
239 + Description: Webapp Deployment Group
240 + Value: !Ref WebappDeploymentGroup
241 + DeploymentBucket:
242 + Description: Deployment bucket
243 + Value: !Ref WebappDeploymentBucket
244 + ApplicationName:
245 + Description: CodeDeploy Application name
246 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + LoadBalancerName: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + LoadBalancerName: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerFullName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + ElbInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: !GetAtt LoadBalancer.LoadBalancerName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: test-LoadB-WCG6QGN19SRO
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.Name
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + targetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + HealthCheckIntervalSeconds: 30
228 + UnhealthyThresholdCount: 2
229 + HealthyThresholdCount: 2
230 + HealthCheckPath: /
231 + Port: 3000
232 + Protocol: HTTP
233 + VpcId:
234 + Ref: VPC
235 +Outputs:
236 + WebappUrl:
237 + Description: Webapp URL
238 + Value: !GetAtt LoadBalancer.DNSName
239 + DeploymentGroup:
240 + Description: Webapp Deployment Group
241 + Value: !Ref WebappDeploymentGroup
242 + DeploymentBucket:
243 + Description: Deployment bucket
244 + Value: !Ref WebappDeploymentBucket
245 + ApplicationName:
246 + Description: CodeDeploy Application name
247 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + TargetGroupAttributes:
228 + - Key: deregistration_delay.timeout_seconds
229 + Value: 60
230 + HealthCheckIntervalSeconds: 30
231 + UnhealthyThresholdCount: 2
232 + HealthyThresholdCount: 2
233 + HealthCheckPath: /
234 + Port: 3000
235 + Protocol: HTTP
236 + VpcId:
237 + Ref: VPC
238 +Outputs:
239 + WebappUrl:
240 + Description: Webapp URL
241 + Value: !GetAtt LoadBalancer.DNSName
242 + DeploymentGroup:
243 + Description: Webapp Deployment Group
244 + Value: !Ref WebappDeploymentGroup
245 + DeploymentBucket:
246 + Description: Deployment bucket
247 + Value: !Ref WebappDeploymentBucket
248 + ApplicationName:
249 + Description: CodeDeploy Application name
250 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64: !Sub |
171 + #! /bin/bash -xe
172 + # update yum just in case
173 + yum update -y
174 + # get node into yum
175 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
176 + # install node and npm in one line
177 + yum install -y nodejs
178 + install pm2 to restart node app
179 + npm i -g pm2@2.4.3
180 + AutoScalingGroup:
181 + Type: AWS::AutoScaling::AutoScalingGroup
182 + Properties:
183 + HealthCheckType: ELB
184 + HealthCheckGracePeriod: 300
185 + MinSize:
186 + Ref: MinSize
187 + MaxSize:
188 + Ref: MaxSize
189 + LaunchConfigurationName:
190 + Ref: WebappLaunchConfig
191 + VPCZoneIdentifier:
192 + Ref: WebappSubnets
193 + TargetGroupARNs:
194 + - Ref: ALBTargetGroup
195 + Tags:
196 + - Key: Name
197 + Value: webapp-example
198 + PropagateAtLaunch: true
199 + ALBListener:
200 + Type: AWS::ElasticLoadBalancingV2::Listener
201 + Properties:
202 + DefaultActions:
203 + -
204 + Type: forward
205 + TargetGroupArn:
206 + Ref: ALBTargetGroup
207 + LoadBalancerArn:
208 + Ref: LoadBalancer
209 + Port: 80
210 + Protocol: HTTP
211 + LoadBalancer:
212 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
213 + Properties:
214 + Name: testLoadbalancer
215 + Scheme: internet-facing
216 + Subnets:
217 + Ref: ALBSubnets
218 + SecurityGroups:
219 + - Ref: ALBSecurityGroup
220 + Tags:
221 + - Key: Name
222 + Value:
223 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
224 + ALBTargetGroup:
225 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
226 + Properties:
227 + TargetGroupAttributes:
228 + - Key: deregistration_delay.timeout_seconds
229 + Value: 30
230 + HealthCheckIntervalSeconds: 30
231 + UnhealthyThresholdCount: 2
232 + HealthyThresholdCount: 2
233 + HealthCheckPath: /
234 + Port: 3000
235 + Protocol: HTTP
236 + VpcId:
237 + Ref: VPC
238 +Outputs:
239 + WebappUrl:
240 + Description: Webapp URL
241 + Value: !GetAtt LoadBalancer.DNSName
242 + DeploymentGroup:
243 + Description: Webapp Deployment Group
244 + Value: !Ref WebappDeploymentGroup
245 + DeploymentBucket:
246 + Description: Deployment bucket
247 + Value: !Ref WebappDeploymentBucket
248 + ApplicationName:
249 + Description: CodeDeploy Application name
250 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # get node into yum
176 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
177 + # install node and npm in one line
178 + yum install -y nodejs
179 + install pm2 to restart node app
180 + npm i -g pm2@2.4.3
181 + AutoScalingGroup:
182 + Type: AWS::AutoScaling::AutoScalingGroup
183 + Properties:
184 + HealthCheckType: ELB
185 + HealthCheckGracePeriod: 300
186 + MinSize:
187 + Ref: MinSize
188 + MaxSize:
189 + Ref: MaxSize
190 + LaunchConfigurationName:
191 + Ref: WebappLaunchConfig
192 + VPCZoneIdentifier:
193 + Ref: WebappSubnets
194 + TargetGroupARNs:
195 + - Ref: ALBTargetGroup
196 + Tags:
197 + - Key: Name
198 + Value: webapp-example
199 + PropagateAtLaunch: true
200 + ALBListener:
201 + Type: AWS::ElasticLoadBalancingV2::Listener
202 + Properties:
203 + DefaultActions:
204 + -
205 + Type: forward
206 + TargetGroupArn:
207 + Ref: ALBTargetGroup
208 + LoadBalancerArn:
209 + Ref: LoadBalancer
210 + Port: 80
211 + Protocol: HTTP
212 + LoadBalancer:
213 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
214 + Properties:
215 + Name: testLoadbalancer
216 + Scheme: internet-facing
217 + Subnets:
218 + Ref: ALBSubnets
219 + SecurityGroups:
220 + - Ref: ALBSecurityGroup
221 + Tags:
222 + - Key: Name
223 + Value:
224 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
225 + ALBTargetGroup:
226 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
227 + Properties:
228 + TargetGroupAttributes:
229 + - Key: deregistration_delay.timeout_seconds
230 + Value: 30
231 + HealthCheckIntervalSeconds: 30
232 + UnhealthyThresholdCount: 2
233 + HealthyThresholdCount: 2
234 + HealthCheckPath: /
235 + Port: 3000
236 + Protocol: HTTP
237 + VpcId:
238 + Ref: VPC
239 +Outputs:
240 + WebappUrl:
241 + Description: Webapp URL
242 + Value: !GetAtt LoadBalancer.DNSName
243 + DeploymentGroup:
244 + Description: Webapp Deployment Group
245 + Value: !Ref WebappDeploymentGroup
246 + DeploymentBucket:
247 + Description: Deployment bucket
248 + Value: !Ref WebappDeploymentBucket
249 + ApplicationName:
250 + Description: CodeDeploy Application name
251 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # get node into yum
176 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
177 + # install node and npm in one line
178 + yum install -y nodejs
179 + # install pm2 to restart node app
180 + npm i -g pm2@2.4.3
181 + AutoScalingGroup:
182 + Type: AWS::AutoScaling::AutoScalingGroup
183 + Properties:
184 + HealthCheckType: ELB
185 + HealthCheckGracePeriod: 300
186 + MinSize:
187 + Ref: MinSize
188 + MaxSize:
189 + Ref: MaxSize
190 + LaunchConfigurationName:
191 + Ref: WebappLaunchConfig
192 + VPCZoneIdentifier:
193 + Ref: WebappSubnets
194 + TargetGroupARNs:
195 + - Ref: ALBTargetGroup
196 + Tags:
197 + - Key: Name
198 + Value: webapp-example
199 + PropagateAtLaunch: true
200 + ALBListener:
201 + Type: AWS::ElasticLoadBalancingV2::Listener
202 + Properties:
203 + DefaultActions:
204 + -
205 + Type: forward
206 + TargetGroupArn:
207 + Ref: ALBTargetGroup
208 + LoadBalancerArn:
209 + Ref: LoadBalancer
210 + Port: 80
211 + Protocol: HTTP
212 + LoadBalancer:
213 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
214 + Properties:
215 + Name: testLoadbalancer
216 + Scheme: internet-facing
217 + Subnets:
218 + Ref: ALBSubnets
219 + SecurityGroups:
220 + - Ref: ALBSecurityGroup
221 + Tags:
222 + - Key: Name
223 + Value:
224 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
225 + ALBTargetGroup:
226 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
227 + Properties:
228 + TargetGroupAttributes:
229 + - Key: deregistration_delay.timeout_seconds
230 + Value: 30
231 + HealthCheckIntervalSeconds: 30
232 + UnhealthyThresholdCount: 2
233 + HealthyThresholdCount: 2
234 + HealthCheckPath: /
235 + Port: 3000
236 + Protocol: HTTP
237 + VpcId:
238 + Ref: VPC
239 +Outputs:
240 + WebappUrl:
241 + Description: Webapp URL
242 + Value: !GetAtt LoadBalancer.DNSName
243 + DeploymentGroup:
244 + Description: Webapp Deployment Group
245 + Value: !Ref WebappDeploymentGroup
246 + DeploymentBucket:
247 + Description: Deployment bucket
248 + Value: !Ref WebappDeploymentBucket
249 + ApplicationName:
250 + Description: CodeDeploy Application name
251 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + yum install -y ruby
176 + cd /home/ec2-user
177 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
178 + chmod +x ./install
179 + ./install auto
180 + # get node into yum
181 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
182 + # install node and npm in one line
183 + yum install -y nodejs
184 + # install pm2 to restart node app
185 + npm i -g pm2@2.4.3
186 + AutoScalingGroup:
187 + Type: AWS::AutoScaling::AutoScalingGroup
188 + Properties:
189 + HealthCheckType: ELB
190 + HealthCheckGracePeriod: 300
191 + MinSize:
192 + Ref: MinSize
193 + MaxSize:
194 + Ref: MaxSize
195 + LaunchConfigurationName:
196 + Ref: WebappLaunchConfig
197 + VPCZoneIdentifier:
198 + Ref: WebappSubnets
199 + TargetGroupARNs:
200 + - Ref: ALBTargetGroup
201 + Tags:
202 + - Key: Name
203 + Value: webapp-example
204 + PropagateAtLaunch: true
205 + ALBListener:
206 + Type: AWS::ElasticLoadBalancingV2::Listener
207 + Properties:
208 + DefaultActions:
209 + -
210 + Type: forward
211 + TargetGroupArn:
212 + Ref: ALBTargetGroup
213 + LoadBalancerArn:
214 + Ref: LoadBalancer
215 + Port: 80
216 + Protocol: HTTP
217 + LoadBalancer:
218 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
219 + Properties:
220 + Name: testLoadbalancer
221 + Scheme: internet-facing
222 + Subnets:
223 + Ref: ALBSubnets
224 + SecurityGroups:
225 + - Ref: ALBSecurityGroup
226 + Tags:
227 + - Key: Name
228 + Value:
229 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
230 + ALBTargetGroup:
231 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
232 + Properties:
233 + TargetGroupAttributes:
234 + - Key: deregistration_delay.timeout_seconds
235 + Value: 30
236 + HealthCheckIntervalSeconds: 30
237 + UnhealthyThresholdCount: 2
238 + HealthyThresholdCount: 2
239 + HealthCheckPath: /
240 + Port: 3000
241 + Protocol: HTTP
242 + VpcId:
243 + Ref: VPC
244 +Outputs:
245 + WebappUrl:
246 + Description: Webapp URL
247 + Value: !GetAtt LoadBalancer.DNSName
248 + DeploymentGroup:
249 + Description: Webapp Deployment Group
250 + Value: !Ref WebappDeploymentGroup
251 + DeploymentBucket:
252 + Description: Deployment bucket
253 + Value: !Ref WebappDeploymentBucket
254 + ApplicationName:
255 + Description: CodeDeploy Application name
256 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
179 + chmod +x ./install
180 + ./install auto
181 + # get node into yum
182 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
183 + # install node and npm in one line
184 + yum install -y nodejs
185 + # install pm2 to restart node app
186 + npm i -g pm2@2.4.3
187 + AutoScalingGroup:
188 + Type: AWS::AutoScaling::AutoScalingGroup
189 + Properties:
190 + HealthCheckType: ELB
191 + HealthCheckGracePeriod: 300
192 + MinSize:
193 + Ref: MinSize
194 + MaxSize:
195 + Ref: MaxSize
196 + LaunchConfigurationName:
197 + Ref: WebappLaunchConfig
198 + VPCZoneIdentifier:
199 + Ref: WebappSubnets
200 + TargetGroupARNs:
201 + - Ref: ALBTargetGroup
202 + Tags:
203 + - Key: Name
204 + Value: webapp-example
205 + PropagateAtLaunch: true
206 + ALBListener:
207 + Type: AWS::ElasticLoadBalancingV2::Listener
208 + Properties:
209 + DefaultActions:
210 + -
211 + Type: forward
212 + TargetGroupArn:
213 + Ref: ALBTargetGroup
214 + LoadBalancerArn:
215 + Ref: LoadBalancer
216 + Port: 80
217 + Protocol: HTTP
218 + LoadBalancer:
219 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
220 + Properties:
221 + Name: testLoadbalancer
222 + Scheme: internet-facing
223 + Subnets:
224 + Ref: ALBSubnets
225 + SecurityGroups:
226 + - Ref: ALBSecurityGroup
227 + Tags:
228 + - Key: Name
229 + Value:
230 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
231 + ALBTargetGroup:
232 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
233 + Properties:
234 + TargetGroupAttributes:
235 + - Key: deregistration_delay.timeout_seconds
236 + Value: 30
237 + HealthCheckIntervalSeconds: 30
238 + UnhealthyThresholdCount: 2
239 + HealthyThresholdCount: 2
240 + HealthCheckPath: /
241 + Port: 3000
242 + Protocol: HTTP
243 + VpcId:
244 + Ref: VPC
245 +Outputs:
246 + WebappUrl:
247 + Description: Webapp URL
248 + Value: !GetAtt LoadBalancer.DNSName
249 + DeploymentGroup:
250 + Description: Webapp Deployment Group
251 + Value: !Ref WebappDeploymentGroup
252 + DeploymentBucket:
253 + Description: Deployment bucket
254 + Value: !Ref WebappDeploymentBucket
255 + ApplicationName:
256 + Description: CodeDeploy Application name
257 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-04fe91441f494c8f4
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + touch ddd.txt
179 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + touch ddd.txt
179 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + touch ddd.txt
179 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + curl -O https://bucket-name.s3.amazonaws.com/latest/install
179 + chmod +x ./install
180 + ./install auto
181 + # get node into yum
182 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
183 + # install node and npm in one line
184 + yum install -y nodejs
185 + # install pm2 to restart node app
186 + npm i -g pm2@2.4.3
187 + AutoScalingGroup:
188 + Type: AWS::AutoScaling::AutoScalingGroup
189 + Properties:
190 + HealthCheckType: ELB
191 + HealthCheckGracePeriod: 300
192 + MinSize:
193 + Ref: MinSize
194 + MaxSize:
195 + Ref: MaxSize
196 + LaunchConfigurationName:
197 + Ref: WebappLaunchConfig
198 + VPCZoneIdentifier:
199 + Ref: WebappSubnets
200 + TargetGroupARNs:
201 + - Ref: ALBTargetGroup
202 + Tags:
203 + - Key: Name
204 + Value: webapp-example
205 + PropagateAtLaunch: true
206 + ALBListener:
207 + Type: AWS::ElasticLoadBalancingV2::Listener
208 + Properties:
209 + DefaultActions:
210 + -
211 + Type: forward
212 + TargetGroupArn:
213 + Ref: ALBTargetGroup
214 + LoadBalancerArn:
215 + Ref: LoadBalancer
216 + Port: 80
217 + Protocol: HTTP
218 + LoadBalancer:
219 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
220 + Properties:
221 + Name: testLoadbalancer
222 + Scheme: internet-facing
223 + Subnets:
224 + Ref: ALBSubnets
225 + SecurityGroups:
226 + - Ref: ALBSecurityGroup
227 + Tags:
228 + - Key: Name
229 + Value:
230 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
231 + ALBTargetGroup:
232 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
233 + Properties:
234 + TargetGroupAttributes:
235 + - Key: deregistration_delay.timeout_seconds
236 + Value: 30
237 + HealthCheckIntervalSeconds: 30
238 + UnhealthyThresholdCount: 2
239 + HealthyThresholdCount: 2
240 + HealthCheckPath: /
241 + Port: 3000
242 + Protocol: HTTP
243 + VpcId:
244 + Ref: VPC
245 +Outputs:
246 + WebappUrl:
247 + Description: Webapp URL
248 + Value: !GetAtt LoadBalancer.DNSName
249 + DeploymentGroup:
250 + Description: Webapp Deployment Group
251 + Value: !Ref WebappDeploymentGroup
252 + DeploymentBucket:
253 + Description: Deployment bucket
254 + Value: !Ref WebappDeploymentBucket
255 + ApplicationName:
256 + Description: CodeDeploy Application name
257 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
179 + chmod +x ./install
180 + ./install auto
181 + # get node into yum
182 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
183 + # install node and npm in one line
184 + yum install -y nodejs
185 + # install pm2 to restart node app
186 + npm i -g pm2@2.4.3
187 + AutoScalingGroup:
188 + Type: AWS::AutoScaling::AutoScalingGroup
189 + Properties:
190 + HealthCheckType: ELB
191 + HealthCheckGracePeriod: 300
192 + MinSize:
193 + Ref: MinSize
194 + MaxSize:
195 + Ref: MaxSize
196 + LaunchConfigurationName:
197 + Ref: WebappLaunchConfig
198 + VPCZoneIdentifier:
199 + Ref: WebappSubnets
200 + TargetGroupARNs:
201 + - Ref: ALBTargetGroup
202 + Tags:
203 + - Key: Name
204 + Value: webapp-example
205 + PropagateAtLaunch: true
206 + ALBListener:
207 + Type: AWS::ElasticLoadBalancingV2::Listener
208 + Properties:
209 + DefaultActions:
210 + -
211 + Type: forward
212 + TargetGroupArn:
213 + Ref: ALBTargetGroup
214 + LoadBalancerArn:
215 + Ref: LoadBalancer
216 + Port: 80
217 + Protocol: HTTP
218 + LoadBalancer:
219 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
220 + Properties:
221 + Name: testLoadbalancer
222 + Scheme: internet-facing
223 + Subnets:
224 + Ref: ALBSubnets
225 + SecurityGroups:
226 + - Ref: ALBSecurityGroup
227 + Tags:
228 + - Key: Name
229 + Value:
230 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
231 + ALBTargetGroup:
232 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
233 + Properties:
234 + TargetGroupAttributes:
235 + - Key: deregistration_delay.timeout_seconds
236 + Value: 30
237 + HealthCheckIntervalSeconds: 30
238 + UnhealthyThresholdCount: 2
239 + HealthyThresholdCount: 2
240 + HealthCheckPath: /
241 + Port: 3000
242 + Protocol: HTTP
243 + VpcId:
244 + Ref: VPC
245 +Outputs:
246 + WebappUrl:
247 + Description: Webapp URL
248 + Value: !GetAtt LoadBalancer.DNSName
249 + DeploymentGroup:
250 + Description: Webapp Deployment Group
251 + Value: !Ref WebappDeploymentGroup
252 + DeploymentBucket:
253 + Description: Deployment bucket
254 + Value: !Ref WebappDeploymentBucket
255 + ApplicationName:
256 + Description: CodeDeploy Application name
257 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + # shoud region change
179 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 1
14 + MaxSize:
15 + Type: Number
16 + Default: 1
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + # shoud region change
179 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + # shoud region change
179 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + AlarmConfiguration:
39 + Alarms:
40 + - Name: codedeploy
41 + Enabled: true
42 + DeploymentGroupName: test-group
43 + ApplicationName: !Ref WebappApplication
44 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
45 + DeploymentConfigName: CodeDeployDefault.OneAtATime
46 + DeploymentStyle:
47 + DeploymentType: IN_PLACE
48 + DeploymentOption: WITH_TRAFFIC_CONTROL
49 + LoadBalancerInfo:
50 + TargetGroupInfoList:
51 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
52 + AutoScalingGroups:
53 + - Ref: AutoScalingGroup
54 + ALBSecurityGroup:
55 + Type: AWS::EC2::SecurityGroup
56 + Properties:
57 + GroupDescription: allow access to ALB from internet
58 + VpcId:
59 + Ref: VPC
60 + SecurityGroupIngress:
61 + - IpProtocol: tcp
62 + FromPort: '80'
63 + ToPort: '80'
64 + CidrIp: 0.0.0.0/0
65 + WebappSecurityGroup:
66 + Type: AWS::EC2::SecurityGroup
67 + Properties:
68 + GroupDescription: allow access to Webapp from ALB
69 + VpcId:
70 + Ref: VPC
71 + SecurityGroupIngress:
72 + - IpProtocol: tcp
73 + FromPort: '3000'
74 + ToPort: '3000'
75 + SourceSecurityGroupId:
76 + Ref: ALBSecurityGroup
77 + - IpProtocol: tcp
78 + FromPort: '22'
79 + ToPort: '22'
80 + CidrIp: 0.0.0.0/0
81 + WebappDeploymentBucket:
82 + Type: "AWS::S3::Bucket"
83 + Properties:
84 + BucketName: 'testtest11324'
85 + CodeDeployRole:
86 + Type: "AWS::IAM::Role"
87 + Properties:
88 + AssumeRolePolicyDocument:
89 + Version: "2012-10-17"
90 + Statement:
91 + -
92 + Effect: "Allow"
93 + Principal:
94 + Service:
95 + - "codedeploy.amazonaws.com"
96 + Action:
97 + - "sts:AssumeRole"
98 + Policies:
99 + -
100 + PolicyName: allow-autoscaling
101 + PolicyDocument:
102 + Version: "2012-10-17"
103 + Statement:
104 + -
105 + Effect: Allow
106 + Action:
107 + - ec2:*
108 + - autoscaling:*
109 + Resource: "*"
110 + -
111 + PolicyName: allow-loadbalance
112 + PolicyDocument:
113 + Version: "2012-10-17"
114 + Statement:
115 + -
116 + Effect: Allow
117 + Action:
118 + - ec2:*
119 + - autoscaling:*
120 + Resource: "*"
121 + -
122 + Effect: Allow
123 + Action:
124 + - iam:CreateServiceLinkedRole
125 + Resource: "*"
126 + -
127 + Effect: Allow
128 + Action:
129 + - elasticloadbalancing:*
130 + Resource: "*"
131 + WebappRole:
132 + Type: "AWS::IAM::Role"
133 + Properties:
134 + AssumeRolePolicyDocument:
135 + Version: "2012-10-17"
136 + Statement:
137 + -
138 + Effect: "Allow"
139 + Principal:
140 + Service:
141 + - "ec2.amazonaws.com"
142 + - "codedeploy.amazonaws.com"
143 + Action:
144 + - "sts:AssumeRole"
145 + Policies:
146 + -
147 + PolicyName: "allow-webapp-deployment-bucket-bucket"
148 + PolicyDocument:
149 + Version: "2012-10-17"
150 + Statement:
151 + -
152 + Effect: "Allow"
153 + Action: "s3:getObject"
154 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
155 + WebappInstanceProfile:
156 + Type: "AWS::IAM::InstanceProfile"
157 + Properties:
158 + Roles:
159 + - Ref: WebappRole
160 + WebappLaunchConfig:
161 + Type: AWS::AutoScaling::LaunchConfiguration
162 + Properties:
163 + AssociatePublicIpAddress: true
164 + ImageId:
165 + Ref: AMIID
166 + InstanceType: t2.micro
167 + KeyName:
168 + Ref: KeyName
169 + SecurityGroups:
170 + - Ref: WebappSecurityGroup
171 + IamInstanceProfile:
172 + Ref: WebappInstanceProfile
173 + UserData:
174 + Fn::Base64:
175 + !Sub |
176 + #! /bin/bash -xe
177 + # update yum just in case
178 + yum update -y
179 + # install codedeploy agent
180 + yum install -y ruby
181 + cd /home/ec2-user
182 + # shoud region change
183 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
184 + chmod +x ./install
185 + ./install auto
186 + # get node into yum
187 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
188 + # install node and npm in one line
189 + yum install -y nodejs
190 + # install pm2 to restart node app
191 + npm i -g pm2@2.4.3
192 + AutoScalingGroup:
193 + Type: AWS::AutoScaling::AutoScalingGroup
194 + Properties:
195 + HealthCheckType: ELB
196 + HealthCheckGracePeriod: 300
197 + MinSize:
198 + Ref: MinSize
199 + MaxSize:
200 + Ref: MaxSize
201 + LaunchConfigurationName:
202 + Ref: WebappLaunchConfig
203 + VPCZoneIdentifier:
204 + Ref: WebappSubnets
205 + TargetGroupARNs:
206 + - Ref: ALBTargetGroup
207 + Tags:
208 + - Key: Name
209 + Value: webapp-example
210 + PropagateAtLaunch: true
211 + ALBListener:
212 + Type: AWS::ElasticLoadBalancingV2::Listener
213 + Properties:
214 + DefaultActions:
215 + -
216 + Type: forward
217 + TargetGroupArn:
218 + Ref: ALBTargetGroup
219 + LoadBalancerArn:
220 + Ref: LoadBalancer
221 + Port: 80
222 + Protocol: HTTP
223 + LoadBalancer:
224 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
225 + Properties:
226 + Name: testLoadbalancer
227 + Scheme: internet-facing
228 + Subnets:
229 + Ref: ALBSubnets
230 + SecurityGroups:
231 + - Ref: ALBSecurityGroup
232 + Tags:
233 + - Key: Name
234 + Value:
235 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
236 + ALBTargetGroup:
237 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
238 + Properties:
239 + TargetGroupAttributes:
240 + - Key: deregistration_delay.timeout_seconds
241 + Value: 30
242 + HealthCheckIntervalSeconds: 30
243 + UnhealthyThresholdCount: 2
244 + HealthyThresholdCount: 2
245 + HealthCheckPath: /
246 + Port: 3000
247 + Protocol: HTTP
248 + VpcId:
249 + Ref: VPC
250 +Outputs:
251 + WebappUrl:
252 + Description: Webapp URL
253 + Value: !GetAtt LoadBalancer.DNSName
254 + DeploymentGroup:
255 + Description: Webapp Deployment Group
256 + Value: !Ref WebappDeploymentGroup
257 + DeploymentBucket:
258 + Description: Deployment bucket
259 + Value: !Ref WebappDeploymentBucket
260 + ApplicationName:
261 + Description: CodeDeploy Application name
262 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + cd /home/ec2-user
178 + # shoud region change
179 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
180 + chmod +x ./install
181 + ./install auto
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 +Outputs:
247 + WebappUrl:
248 + Description: Webapp URL
249 + Value: !GetAtt LoadBalancer.DNSName
250 + DeploymentGroup:
251 + Description: Webapp Deployment Group
252 + Value: !Ref WebappDeploymentGroup
253 + DeploymentBucket:
254 + Description: Deployment bucket
255 + Value: !Ref WebappDeploymentBucket
256 + ApplicationName:
257 + Description: CodeDeploy Application name
258 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + yum install -y wget
178 + cd /home/ec2-user
179 + # shoud region change
180 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
181 + chmod +x ./install
182 + ./install auto
183 + # cloudwatch
184 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
185 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
186 + chmod +x ./awslogs-agent-setup.py
187 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
188 + sudo mkdir -p /var/awslogs/etc/config
189 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
190 + sudo service awslogs restart
191 + # get node into yum
192 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
193 + # install node and npm in one line
194 + yum install -y nodejs
195 + # install pm2 to restart node app
196 + npm i -g pm2@2.4.3
197 + AutoScalingGroup:
198 + Type: AWS::AutoScaling::AutoScalingGroup
199 + Properties:
200 + HealthCheckType: ELB
201 + HealthCheckGracePeriod: 300
202 + MinSize:
203 + Ref: MinSize
204 + MaxSize:
205 + Ref: MaxSize
206 + LaunchConfigurationName:
207 + Ref: WebappLaunchConfig
208 + VPCZoneIdentifier:
209 + Ref: WebappSubnets
210 + TargetGroupARNs:
211 + - Ref: ALBTargetGroup
212 + Tags:
213 + - Key: Name
214 + Value: webapp-example
215 + PropagateAtLaunch: true
216 + ALBListener:
217 + Type: AWS::ElasticLoadBalancingV2::Listener
218 + Properties:
219 + DefaultActions:
220 + -
221 + Type: forward
222 + TargetGroupArn:
223 + Ref: ALBTargetGroup
224 + LoadBalancerArn:
225 + Ref: LoadBalancer
226 + Port: 80
227 + Protocol: HTTP
228 + LoadBalancer:
229 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
230 + Properties:
231 + Name: testLoadbalancer
232 + Scheme: internet-facing
233 + Subnets:
234 + Ref: ALBSubnets
235 + SecurityGroups:
236 + - Ref: ALBSecurityGroup
237 + Tags:
238 + - Key: Name
239 + Value:
240 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
241 + ALBTargetGroup:
242 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
243 + Properties:
244 + TargetGroupAttributes:
245 + - Key: deregistration_delay.timeout_seconds
246 + Value: 30
247 + HealthCheckIntervalSeconds: 30
248 + UnhealthyThresholdCount: 2
249 + HealthyThresholdCount: 2
250 + HealthCheckPath: /
251 + Port: 3000
252 + Protocol: HTTP
253 + VpcId:
254 + Ref: VPC
255 +Outputs:
256 + WebappUrl:
257 + Description: Webapp URL
258 + Value: !GetAtt LoadBalancer.DNSName
259 + DeploymentGroup:
260 + Description: Webapp Deployment Group
261 + Value: !Ref WebappDeploymentGroup
262 + DeploymentBucket:
263 + Description: Deployment bucket
264 + Value: !Ref WebappDeploymentBucket
265 + ApplicationName:
266 + Description: CodeDeploy Application name
267 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + Policies:
142 + -
143 + PolicyName: "allow-webapp-deployment-bucket-bucket"
144 + PolicyDocument:
145 + Version: "2012-10-17"
146 + Statement:
147 + -
148 + Effect: "Allow"
149 + Action: "s3:getObject"
150 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + WebappLaunchConfig:
157 + Type: AWS::AutoScaling::LaunchConfiguration
158 + Properties:
159 + AssociatePublicIpAddress: true
160 + ImageId:
161 + Ref: AMIID
162 + InstanceType: t2.micro
163 + KeyName:
164 + Ref: KeyName
165 + SecurityGroups:
166 + - Ref: WebappSecurityGroup
167 + IamInstanceProfile:
168 + Ref: WebappInstanceProfile
169 + UserData:
170 + Fn::Base64:
171 + !Sub |
172 + #! /bin/bash -xe
173 + # update yum just in case
174 + yum update -y
175 + # install codedeploy agent
176 + yum install -y ruby
177 + yum install -y wget
178 + cd /home/ec2-user
179 + # shoud region change
180 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
181 + chmod +x ./install
182 + ./install auto
183 + # cloudwatch
184 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
185 + wget https://s3.amazonaws.com/aws-codedeploy-ap-northeast-2/cloudwatch/codedeploy_logs.conf
186 + chmod +x ./awslogs-agent-setup.py
187 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-ap-northeast-2/cloudwatch/awslogs.conf
188 + sudo mkdir -p /var/awslogs/etc/config
189 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
190 + sudo service awslogs restart
191 + # get node into yum
192 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
193 + # install node and npm in one line
194 + yum install -y nodejs
195 + # install pm2 to restart node app
196 + npm i -g pm2@2.4.3
197 + AutoScalingGroup:
198 + Type: AWS::AutoScaling::AutoScalingGroup
199 + Properties:
200 + HealthCheckType: ELB
201 + HealthCheckGracePeriod: 300
202 + MinSize:
203 + Ref: MinSize
204 + MaxSize:
205 + Ref: MaxSize
206 + LaunchConfigurationName:
207 + Ref: WebappLaunchConfig
208 + VPCZoneIdentifier:
209 + Ref: WebappSubnets
210 + TargetGroupARNs:
211 + - Ref: ALBTargetGroup
212 + Tags:
213 + - Key: Name
214 + Value: webapp-example
215 + PropagateAtLaunch: true
216 + ALBListener:
217 + Type: AWS::ElasticLoadBalancingV2::Listener
218 + Properties:
219 + DefaultActions:
220 + -
221 + Type: forward
222 + TargetGroupArn:
223 + Ref: ALBTargetGroup
224 + LoadBalancerArn:
225 + Ref: LoadBalancer
226 + Port: 80
227 + Protocol: HTTP
228 + LoadBalancer:
229 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
230 + Properties:
231 + Name: testLoadbalancer
232 + Scheme: internet-facing
233 + Subnets:
234 + Ref: ALBSubnets
235 + SecurityGroups:
236 + - Ref: ALBSecurityGroup
237 + Tags:
238 + - Key: Name
239 + Value:
240 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
241 + ALBTargetGroup:
242 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
243 + Properties:
244 + TargetGroupAttributes:
245 + - Key: deregistration_delay.timeout_seconds
246 + Value: 30
247 + HealthCheckIntervalSeconds: 30
248 + UnhealthyThresholdCount: 2
249 + HealthyThresholdCount: 2
250 + HealthCheckPath: /
251 + Port: 3000
252 + Protocol: HTTP
253 + VpcId:
254 + Ref: VPC
255 +Outputs:
256 + WebappUrl:
257 + Description: Webapp URL
258 + Value: !GetAtt LoadBalancer.DNSName
259 + DeploymentGroup:
260 + Description: Webapp Deployment Group
261 + Value: !Ref WebappDeploymentGroup
262 + DeploymentBucket:
263 + Description: Deployment bucket
264 + Value: !Ref WebappDeploymentBucket
265 + ApplicationName:
266 + Description: CodeDeploy Application name
267 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://s3.amazonaws.com/aws-codedeploy-ap-northeast-2/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-ap-northeast-2/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://s3.amazonaws.com/aws-codedeploy-ap-northeast-2/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-ap-northeast-2/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-ap-northeast-2/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aaws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget wget https://s3.amazonaws.com/aws-codedeploy-ap-northeast-2/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aaws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://s3.amazonaws.com/aws-codedeploy-ap-northeast-2/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aaws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aaws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aaws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
186 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
186 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + sudo rpm -U ./amazon-cloudwatch-agent.rpm
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
186 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + sudo rpm -U ./amazon-cloudwatch-agent.rpm
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf -s
190 + sudo mkdir -p /var/awslogs/etc/config
191 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
192 + sudo service awslogs restart
193 + # get node into yum
194 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
195 + # install node and npm in one line
196 + yum install -y nodejs
197 + # install pm2 to restart node app
198 + npm i -g pm2@2.4.3
199 + AutoScalingGroup:
200 + Type: AWS::AutoScaling::AutoScalingGroup
201 + Properties:
202 + HealthCheckType: ELB
203 + HealthCheckGracePeriod: 300
204 + MinSize:
205 + Ref: MinSize
206 + MaxSize:
207 + Ref: MaxSize
208 + LaunchConfigurationName:
209 + Ref: WebappLaunchConfig
210 + VPCZoneIdentifier:
211 + Ref: WebappSubnets
212 + TargetGroupARNs:
213 + - Ref: ALBTargetGroup
214 + Tags:
215 + - Key: Name
216 + Value: webapp-example
217 + PropagateAtLaunch: true
218 + ALBListener:
219 + Type: AWS::ElasticLoadBalancingV2::Listener
220 + Properties:
221 + DefaultActions:
222 + -
223 + Type: forward
224 + TargetGroupArn:
225 + Ref: ALBTargetGroup
226 + LoadBalancerArn:
227 + Ref: LoadBalancer
228 + Port: 80
229 + Protocol: HTTP
230 + LoadBalancer:
231 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
232 + Properties:
233 + Name: testLoadbalancer
234 + Scheme: internet-facing
235 + Subnets:
236 + Ref: ALBSubnets
237 + SecurityGroups:
238 + - Ref: ALBSecurityGroup
239 + Tags:
240 + - Key: Name
241 + Value:
242 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
243 + ALBTargetGroup:
244 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
245 + Properties:
246 + TargetGroupAttributes:
247 + - Key: deregistration_delay.timeout_seconds
248 + Value: 30
249 + HealthCheckIntervalSeconds: 30
250 + UnhealthyThresholdCount: 2
251 + HealthyThresholdCount: 2
252 + HealthCheckPath: /
253 + Port: 3000
254 + Protocol: HTTP
255 + VpcId:
256 + Ref: VPC
257 +Outputs:
258 + WebappUrl:
259 + Description: Webapp URL
260 + Value: !GetAtt LoadBalancer.DNSName
261 + DeploymentGroup:
262 + Description: Webapp Deployment Group
263 + Value: !Ref WebappDeploymentGroup
264 + DeploymentBucket:
265 + Description: Deployment bucket
266 + Value: !Ref WebappDeploymentBucket
267 + ApplicationName:
268 + Description: CodeDeploy Application name
269 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 +wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 +chmod +x ./awslogs-agent-setup.py
188 +sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 +sudo mkdir -p /var/awslogs/etc/config
190 +sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 +sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "cloudwatch.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + WebappInstanceProfile:
153 + Type: "AWS::IAM::InstanceProfile"
154 + Properties:
155 + Roles:
156 + - Ref: WebappRole
157 + WebappLaunchConfig:
158 + Type: AWS::AutoScaling::LaunchConfiguration
159 + Properties:
160 + AssociatePublicIpAddress: true
161 + ImageId:
162 + Ref: AMIID
163 + InstanceType: t2.micro
164 + KeyName:
165 + Ref: KeyName
166 + SecurityGroups:
167 + - Ref: WebappSecurityGroup
168 + IamInstanceProfile:
169 + Ref: WebappInstanceProfile
170 + UserData:
171 + Fn::Base64:
172 + !Sub |
173 + #! /bin/bash -xe
174 + # update yum just in case
175 + yum update -y
176 + # install codedeploy agent
177 + yum install -y ruby
178 + yum install -y wget
179 + cd /home/ec2-user
180 + # shoud region change
181 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
182 + chmod +x ./install
183 + ./install auto
184 + # cloudwatch
185 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
186 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
187 + chmod +x ./awslogs-agent-setup.py
188 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
189 + sudo mkdir -p /var/awslogs/etc/config
190 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
191 + sudo service awslogs restart
192 + # get node into yum
193 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
194 + # install node and npm in one line
195 + yum install -y nodejs
196 + # install pm2 to restart node app
197 + npm i -g pm2@2.4.3
198 + AutoScalingGroup:
199 + Type: AWS::AutoScaling::AutoScalingGroup
200 + Properties:
201 + HealthCheckType: ELB
202 + HealthCheckGracePeriod: 300
203 + MinSize:
204 + Ref: MinSize
205 + MaxSize:
206 + Ref: MaxSize
207 + LaunchConfigurationName:
208 + Ref: WebappLaunchConfig
209 + VPCZoneIdentifier:
210 + Ref: WebappSubnets
211 + TargetGroupARNs:
212 + - Ref: ALBTargetGroup
213 + Tags:
214 + - Key: Name
215 + Value: webapp-example
216 + PropagateAtLaunch: true
217 + ALBListener:
218 + Type: AWS::ElasticLoadBalancingV2::Listener
219 + Properties:
220 + DefaultActions:
221 + -
222 + Type: forward
223 + TargetGroupArn:
224 + Ref: ALBTargetGroup
225 + LoadBalancerArn:
226 + Ref: LoadBalancer
227 + Port: 80
228 + Protocol: HTTP
229 + LoadBalancer:
230 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
231 + Properties:
232 + Name: testLoadbalancer
233 + Scheme: internet-facing
234 + Subnets:
235 + Ref: ALBSubnets
236 + SecurityGroups:
237 + - Ref: ALBSecurityGroup
238 + Tags:
239 + - Key: Name
240 + Value:
241 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
242 + ALBTargetGroup:
243 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
244 + Properties:
245 + TargetGroupAttributes:
246 + - Key: deregistration_delay.timeout_seconds
247 + Value: 30
248 + HealthCheckIntervalSeconds: 30
249 + UnhealthyThresholdCount: 2
250 + HealthyThresholdCount: 2
251 + HealthCheckPath: /
252 + Port: 3000
253 + Protocol: HTTP
254 + VpcId:
255 + Ref: VPC
256 +Outputs:
257 + WebappUrl:
258 + Description: Webapp URL
259 + Value: !GetAtt LoadBalancer.DNSName
260 + DeploymentGroup:
261 + Description: Webapp Deployment Group
262 + Value: !Ref WebappDeploymentGroup
263 + DeploymentBucket:
264 + Description: Deployment bucket
265 + Value: !Ref WebappDeploymentBucket
266 + ApplicationName:
267 + Description: CodeDeploy Application name
268 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + wget https://s3.amazonaws.com/aws-cloudwatch/downloads/latest/awslogs-agent-setup.py
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + chmod +x ./awslogs-agent-setup.py
196 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
197 + sudo mkdir -p /var/awslogs/etc/config
198 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
199 + sudo service awslogs restart
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + chmod +x ./awslogs-agent-setup.py
196 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
197 + sudo mkdir -p /var/awslogs/etc/config
198 + sudo cp codedeploy_logs.conf /var/awslogs/etc/config/
199 + sudo service awslogs restart
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf
196 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
197 + sudo mkdir -p /var/awslogs/etc/config
198 + sudo cp codedeploy_logs.conf /etc/awslogs/
199 + sudo service awslogs restart
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf
196 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
197 + sudo mkdir -p /var/awslogs/etc/config
198 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
199 + sudo service awslogs restart
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
196 + sudo python awslogs-agent-setup.py -n -r REGION -c s3://aws-codedeploy-us-east-1/cloudwatch/awslogs.conf
197 + sudo mkdir -p /var/awslogs/etc/config
198 + sudo service awslogs restart
199 + # get node into yum
200 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
201 + # install node and npm in one line
202 + yum install -y nodejs
203 + # install pm2 to restart node app
204 + npm i -g pm2@2.4.3
205 + AutoScalingGroup:
206 + Type: AWS::AutoScaling::AutoScalingGroup
207 + Properties:
208 + HealthCheckType: ELB
209 + HealthCheckGracePeriod: 300
210 + MinSize:
211 + Ref: MinSize
212 + MaxSize:
213 + Ref: MaxSize
214 + LaunchConfigurationName:
215 + Ref: WebappLaunchConfig
216 + VPCZoneIdentifier:
217 + Ref: WebappSubnets
218 + TargetGroupARNs:
219 + - Ref: ALBTargetGroup
220 + Tags:
221 + - Key: Name
222 + Value: webapp-example
223 + PropagateAtLaunch: true
224 + ALBListener:
225 + Type: AWS::ElasticLoadBalancingV2::Listener
226 + Properties:
227 + DefaultActions:
228 + -
229 + Type: forward
230 + TargetGroupArn:
231 + Ref: ALBTargetGroup
232 + LoadBalancerArn:
233 + Ref: LoadBalancer
234 + Port: 80
235 + Protocol: HTTP
236 + LoadBalancer:
237 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
238 + Properties:
239 + Name: testLoadbalancer
240 + Scheme: internet-facing
241 + Subnets:
242 + Ref: ALBSubnets
243 + SecurityGroups:
244 + - Ref: ALBSecurityGroup
245 + Tags:
246 + - Key: Name
247 + Value:
248 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
249 + ALBTargetGroup:
250 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
251 + Properties:
252 + TargetGroupAttributes:
253 + - Key: deregistration_delay.timeout_seconds
254 + Value: 30
255 + HealthCheckIntervalSeconds: 30
256 + UnhealthyThresholdCount: 2
257 + HealthyThresholdCount: 2
258 + HealthCheckPath: /
259 + Port: 3000
260 + Protocol: HTTP
261 + VpcId:
262 + Ref: VPC
263 +Outputs:
264 + WebappUrl:
265 + Description: Webapp URL
266 + Value: !GetAtt LoadBalancer.DNSName
267 + DeploymentGroup:
268 + Description: Webapp Deployment Group
269 + Value: !Ref WebappDeploymentGroup
270 + DeploymentBucket:
271 + Description: Deployment bucket
272 + Value: !Ref WebappDeploymentBucket
273 + ApplicationName:
274 + Description: CodeDeploy Application name
275 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + Resource: "*"
149 + Policies:
150 + -
151 + PolicyName: "allow-webapp-deployment-bucket-bucket"
152 + PolicyDocument:
153 + Version: "2012-10-17"
154 + Statement:
155 + -
156 + Effect: "Allow"
157 + Action: "s3:getObject"
158 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
159 + WebappInstanceProfile:
160 + Type: "AWS::IAM::InstanceProfile"
161 + Properties:
162 + Roles:
163 + - Ref: WebappRole
164 + WebappLaunchConfig:
165 + Type: AWS::AutoScaling::LaunchConfiguration
166 + Properties:
167 + AssociatePublicIpAddress: true
168 + ImageId:
169 + Ref: AMIID
170 + InstanceType: t2.micro
171 + KeyName:
172 + Ref: KeyName
173 + SecurityGroups:
174 + - Ref: WebappSecurityGroup
175 + IamInstanceProfile:
176 + Ref: WebappInstanceProfile
177 + UserData:
178 + Fn::Base64:
179 + !Sub |
180 + #! /bin/bash -xe
181 + # update yum just in case
182 + yum update -y
183 + # install codedeploy agent
184 + yum install -y ruby
185 + yum install -y wget
186 + cd /home/ec2-user
187 + # shoud region change
188 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
189 + chmod +x ./install
190 + ./install auto
191 + # cloudwatch
192 + sudo yum install -y awslogs
193 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
194 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
195 + sudo systemctl start awslogsd
196 + # get node into yum
197 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
198 + # install node and npm in one line
199 + yum install -y nodejs
200 + # install pm2 to restart node app
201 + npm i -g pm2@2.4.3
202 + AutoScalingGroup:
203 + Type: AWS::AutoScaling::AutoScalingGroup
204 + Properties:
205 + HealthCheckType: ELB
206 + HealthCheckGracePeriod: 300
207 + MinSize:
208 + Ref: MinSize
209 + MaxSize:
210 + Ref: MaxSize
211 + LaunchConfigurationName:
212 + Ref: WebappLaunchConfig
213 + VPCZoneIdentifier:
214 + Ref: WebappSubnets
215 + TargetGroupARNs:
216 + - Ref: ALBTargetGroup
217 + Tags:
218 + - Key: Name
219 + Value: webapp-example
220 + PropagateAtLaunch: true
221 + ALBListener:
222 + Type: AWS::ElasticLoadBalancingV2::Listener
223 + Properties:
224 + DefaultActions:
225 + -
226 + Type: forward
227 + TargetGroupArn:
228 + Ref: ALBTargetGroup
229 + LoadBalancerArn:
230 + Ref: LoadBalancer
231 + Port: 80
232 + Protocol: HTTP
233 + LoadBalancer:
234 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
235 + Properties:
236 + Name: testLoadbalancer
237 + Scheme: internet-facing
238 + Subnets:
239 + Ref: ALBSubnets
240 + SecurityGroups:
241 + - Ref: ALBSecurityGroup
242 + Tags:
243 + - Key: Name
244 + Value:
245 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
246 + ALBTargetGroup:
247 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
248 + Properties:
249 + TargetGroupAttributes:
250 + - Key: deregistration_delay.timeout_seconds
251 + Value: 30
252 + HealthCheckIntervalSeconds: 30
253 + UnhealthyThresholdCount: 2
254 + HealthyThresholdCount: 2
255 + HealthCheckPath: /
256 + Port: 3000
257 + Protocol: HTTP
258 + VpcId:
259 + Ref: VPC
260 +Outputs:
261 + WebappUrl:
262 + Description: Webapp URL
263 + Value: !GetAtt LoadBalancer.DNSName
264 + DeploymentGroup:
265 + Description: Webapp Deployment Group
266 + Value: !Ref WebappDeploymentGroup
267 + DeploymentBucket:
268 + Description: Deployment bucket
269 + Value: !Ref WebappDeploymentBucket
270 + ApplicationName:
271 + Description: CodeDeploy Application name
272 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Resource: "*"
143 + Policies:
144 + -
145 + PolicyName: "allow-webapp-deployment-bucket-bucket"
146 + PolicyDocument:
147 + Version: "2012-10-17"
148 + Statement:
149 + -
150 + Effect: "Allow"
151 + Action: "s3:getObject"
152 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
153 + WebappInstanceProfile:
154 + Type: "AWS::IAM::InstanceProfile"
155 + Properties:
156 + Roles:
157 + - Ref: WebappRole
158 + WebappLaunchConfig:
159 + Type: AWS::AutoScaling::LaunchConfiguration
160 + Properties:
161 + AssociatePublicIpAddress: true
162 + ImageId:
163 + Ref: AMIID
164 + InstanceType: t2.micro
165 + KeyName:
166 + Ref: KeyName
167 + SecurityGroups:
168 + - Ref: WebappSecurityGroup
169 + IamInstanceProfile:
170 + Ref: WebappInstanceProfile
171 + UserData:
172 + Fn::Base64:
173 + !Sub |
174 + #! /bin/bash -xe
175 + # update yum just in case
176 + yum update -y
177 + # install codedeploy agent
178 + yum install -y ruby
179 + yum install -y wget
180 + cd /home/ec2-user
181 + # shoud region change
182 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
183 + chmod +x ./install
184 + ./install auto
185 + # cloudwatch
186 + sudo yum install -y awslogs
187 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
188 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
189 + sudo systemctl start awslogsd
190 + # get node into yum
191 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
192 + # install node and npm in one line
193 + yum install -y nodejs
194 + # install pm2 to restart node app
195 + npm i -g pm2@2.4.3
196 + AutoScalingGroup:
197 + Type: AWS::AutoScaling::AutoScalingGroup
198 + Properties:
199 + HealthCheckType: ELB
200 + HealthCheckGracePeriod: 300
201 + MinSize:
202 + Ref: MinSize
203 + MaxSize:
204 + Ref: MaxSize
205 + LaunchConfigurationName:
206 + Ref: WebappLaunchConfig
207 + VPCZoneIdentifier:
208 + Ref: WebappSubnets
209 + TargetGroupARNs:
210 + - Ref: ALBTargetGroup
211 + Tags:
212 + - Key: Name
213 + Value: webapp-example
214 + PropagateAtLaunch: true
215 + ALBListener:
216 + Type: AWS::ElasticLoadBalancingV2::Listener
217 + Properties:
218 + DefaultActions:
219 + -
220 + Type: forward
221 + TargetGroupArn:
222 + Ref: ALBTargetGroup
223 + LoadBalancerArn:
224 + Ref: LoadBalancer
225 + Port: 80
226 + Protocol: HTTP
227 + LoadBalancer:
228 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
229 + Properties:
230 + Name: testLoadbalancer
231 + Scheme: internet-facing
232 + Subnets:
233 + Ref: ALBSubnets
234 + SecurityGroups:
235 + - Ref: ALBSecurityGroup
236 + Tags:
237 + - Key: Name
238 + Value:
239 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
240 + ALBTargetGroup:
241 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
242 + Properties:
243 + TargetGroupAttributes:
244 + - Key: deregistration_delay.timeout_seconds
245 + Value: 30
246 + HealthCheckIntervalSeconds: 30
247 + UnhealthyThresholdCount: 2
248 + HealthyThresholdCount: 2
249 + HealthCheckPath: /
250 + Port: 3000
251 + Protocol: HTTP
252 + VpcId:
253 + Ref: VPC
254 +Outputs:
255 + WebappUrl:
256 + Description: Webapp URL
257 + Value: !GetAtt LoadBalancer.DNSName
258 + DeploymentGroup:
259 + Description: Webapp Deployment Group
260 + Value: !Ref WebappDeploymentGroup
261 + DeploymentBucket:
262 + Description: Deployment bucket
263 + Value: !Ref WebappDeploymentBucket
264 + ApplicationName:
265 + Description: CodeDeploy Application name
266 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + -
142 + Effect: Allow
143 + Action:
144 + - autoscaling:*
145 + - cloudwatch:*
146 + - logs:*
147 + - sns:*
148 + Resource: "*"
149 + Policies:
150 + -
151 + PolicyName: "allow-webapp-deployment-bucket-bucket"
152 + PolicyDocument:
153 + Version: "2012-10-17"
154 + Statement:
155 + -
156 + Effect: "Allow"
157 + Action: "s3:getObject"
158 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
159 + WebappInstanceProfile:
160 + Type: "AWS::IAM::InstanceProfile"
161 + Properties:
162 + Roles:
163 + - Ref: WebappRole
164 + WebappLaunchConfig:
165 + Type: AWS::AutoScaling::LaunchConfiguration
166 + Properties:
167 + AssociatePublicIpAddress: true
168 + ImageId:
169 + Ref: AMIID
170 + InstanceType: t2.micro
171 + KeyName:
172 + Ref: KeyName
173 + SecurityGroups:
174 + - Ref: WebappSecurityGroup
175 + IamInstanceProfile:
176 + Ref: WebappInstanceProfile
177 + UserData:
178 + Fn::Base64:
179 + !Sub |
180 + #! /bin/bash -xe
181 + # update yum just in case
182 + yum update -y
183 + # install codedeploy agent
184 + yum install -y ruby
185 + yum install -y wget
186 + cd /home/ec2-user
187 + # shoud region change
188 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
189 + chmod +x ./install
190 + ./install auto
191 + # cloudwatch
192 + sudo yum install -y awslogs
193 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
194 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
195 + sudo systemctl start awslogsd
196 + # get node into yum
197 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
198 + # install node and npm in one line
199 + yum install -y nodejs
200 + # install pm2 to restart node app
201 + npm i -g pm2@2.4.3
202 + AutoScalingGroup:
203 + Type: AWS::AutoScaling::AutoScalingGroup
204 + Properties:
205 + HealthCheckType: ELB
206 + HealthCheckGracePeriod: 300
207 + MinSize:
208 + Ref: MinSize
209 + MaxSize:
210 + Ref: MaxSize
211 + LaunchConfigurationName:
212 + Ref: WebappLaunchConfig
213 + VPCZoneIdentifier:
214 + Ref: WebappSubnets
215 + TargetGroupARNs:
216 + - Ref: ALBTargetGroup
217 + Tags:
218 + - Key: Name
219 + Value: webapp-example
220 + PropagateAtLaunch: true
221 + ALBListener:
222 + Type: AWS::ElasticLoadBalancingV2::Listener
223 + Properties:
224 + DefaultActions:
225 + -
226 + Type: forward
227 + TargetGroupArn:
228 + Ref: ALBTargetGroup
229 + LoadBalancerArn:
230 + Ref: LoadBalancer
231 + Port: 80
232 + Protocol: HTTP
233 + LoadBalancer:
234 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
235 + Properties:
236 + Name: testLoadbalancer
237 + Scheme: internet-facing
238 + Subnets:
239 + Ref: ALBSubnets
240 + SecurityGroups:
241 + - Ref: ALBSecurityGroup
242 + Tags:
243 + - Key: Name
244 + Value:
245 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
246 + ALBTargetGroup:
247 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
248 + Properties:
249 + TargetGroupAttributes:
250 + - Key: deregistration_delay.timeout_seconds
251 + Value: 30
252 + HealthCheckIntervalSeconds: 30
253 + UnhealthyThresholdCount: 2
254 + HealthyThresholdCount: 2
255 + HealthCheckPath: /
256 + Port: 3000
257 + Protocol: HTTP
258 + VpcId:
259 + Ref: VPC
260 +Outputs:
261 + WebappUrl:
262 + Description: Webapp URL
263 + Value: !GetAtt LoadBalancer.DNSName
264 + DeploymentGroup:
265 + Description: Webapp Deployment Group
266 + Value: !Ref WebappDeploymentGroup
267 + DeploymentBucket:
268 + Description: Deployment bucket
269 + Value: !Ref WebappDeploymentBucket
270 + ApplicationName:
271 + Description: CodeDeploy Application name
272 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + -
142 + Effect: Allow
143 + Action:
144 + - autoscaling:*
145 + - cloudwatch:*
146 + - logs:*
147 + Resource: "*"
148 + Policies:
149 + -
150 + PolicyName: "allow-webapp-deployment-bucket-bucket"
151 + PolicyDocument:
152 + Version: "2012-10-17"
153 + Statement:
154 + -
155 + Effect: "Allow"
156 + Action: "s3:getObject"
157 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
158 + WebappInstanceProfile:
159 + Type: "AWS::IAM::InstanceProfile"
160 + Properties:
161 + Roles:
162 + - Ref: WebappRole
163 + WebappLaunchConfig:
164 + Type: AWS::AutoScaling::LaunchConfiguration
165 + Properties:
166 + AssociatePublicIpAddress: true
167 + ImageId:
168 + Ref: AMIID
169 + InstanceType: t2.micro
170 + KeyName:
171 + Ref: KeyName
172 + SecurityGroups:
173 + - Ref: WebappSecurityGroup
174 + IamInstanceProfile:
175 + Ref: WebappInstanceProfile
176 + UserData:
177 + Fn::Base64:
178 + !Sub |
179 + #! /bin/bash -xe
180 + # update yum just in case
181 + yum update -y
182 + # install codedeploy agent
183 + yum install -y ruby
184 + yum install -y wget
185 + cd /home/ec2-user
186 + # shoud region change
187 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
188 + chmod +x ./install
189 + ./install auto
190 + # cloudwatch
191 + sudo yum install -y awslogs
192 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
193 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
194 + sudo systemctl start awslogsd
195 + # get node into yum
196 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
197 + # install node and npm in one line
198 + yum install -y nodejs
199 + # install pm2 to restart node app
200 + npm i -g pm2@2.4.3
201 + AutoScalingGroup:
202 + Type: AWS::AutoScaling::AutoScalingGroup
203 + Properties:
204 + HealthCheckType: ELB
205 + HealthCheckGracePeriod: 300
206 + MinSize:
207 + Ref: MinSize
208 + MaxSize:
209 + Ref: MaxSize
210 + LaunchConfigurationName:
211 + Ref: WebappLaunchConfig
212 + VPCZoneIdentifier:
213 + Ref: WebappSubnets
214 + TargetGroupARNs:
215 + - Ref: ALBTargetGroup
216 + Tags:
217 + - Key: Name
218 + Value: webapp-example
219 + PropagateAtLaunch: true
220 + ALBListener:
221 + Type: AWS::ElasticLoadBalancingV2::Listener
222 + Properties:
223 + DefaultActions:
224 + -
225 + Type: forward
226 + TargetGroupArn:
227 + Ref: ALBTargetGroup
228 + LoadBalancerArn:
229 + Ref: LoadBalancer
230 + Port: 80
231 + Protocol: HTTP
232 + LoadBalancer:
233 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
234 + Properties:
235 + Name: testLoadbalancer
236 + Scheme: internet-facing
237 + Subnets:
238 + Ref: ALBSubnets
239 + SecurityGroups:
240 + - Ref: ALBSecurityGroup
241 + Tags:
242 + - Key: Name
243 + Value:
244 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
245 + ALBTargetGroup:
246 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
247 + Properties:
248 + TargetGroupAttributes:
249 + - Key: deregistration_delay.timeout_seconds
250 + Value: 30
251 + HealthCheckIntervalSeconds: 30
252 + UnhealthyThresholdCount: 2
253 + HealthyThresholdCount: 2
254 + HealthCheckPath: /
255 + Port: 3000
256 + Protocol: HTTP
257 + VpcId:
258 + Ref: VPC
259 +Outputs:
260 + WebappUrl:
261 + Description: Webapp URL
262 + Value: !GetAtt LoadBalancer.DNSName
263 + DeploymentGroup:
264 + Description: Webapp Deployment Group
265 + Value: !Ref WebappDeploymentGroup
266 + DeploymentBucket:
267 + Description: Deployment bucket
268 + Value: !Ref WebappDeploymentBucket
269 + ApplicationName:
270 + Description: CodeDeploy Application name
271 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + Action:
140 + - "sts:AssumeRole"
141 + -
142 + Effect: Allow
143 + Action:
144 + - autoscaling:*
145 + - cloudwatch:*
146 + - logs:*
147 + Resource: "*"
148 + Policies:
149 + -
150 + PolicyName: "allow-webapp-deployment-bucket-bucket"
151 + PolicyDocument:
152 + Version: "2012-10-17"
153 + Statement:
154 + -
155 + Effect: "Allow"
156 + Action: "s3:getObject"
157 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
158 + WebappInstanceProfile:
159 + Type: "AWS::IAM::InstanceProfile"
160 + Properties:
161 + Roles:
162 + - Ref: WebappRole
163 + WebappLaunchConfig:
164 + Type: AWS::AutoScaling::LaunchConfiguration
165 + Properties:
166 + AssociatePublicIpAddress: true
167 + ImageId:
168 + Ref: AMIID
169 + InstanceType: t2.micro
170 + KeyName:
171 + Ref: KeyName
172 + SecurityGroups:
173 + - Ref: WebappSecurityGroup
174 + IamInstanceProfile:
175 + Ref: WebappInstanceProfile
176 + UserData:
177 + Fn::Base64:
178 + !Sub |
179 + #! /bin/bash -xe
180 + # update yum just in case
181 + yum update -y
182 + # install codedeploy agent
183 + yum install -y ruby
184 + yum install -y wget
185 + cd /home/ec2-user
186 + # shoud region change
187 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
188 + chmod +x ./install
189 + ./install auto
190 + # cloudwatch
191 + sudo yum install -y awslogs
192 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
193 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
194 + sudo systemctl start awslogsd
195 + # get node into yum
196 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
197 + # install node and npm in one line
198 + yum install -y nodejs
199 + # install pm2 to restart node app
200 + npm i -g pm2@2.4.3
201 + AutoScalingGroup:
202 + Type: AWS::AutoScaling::AutoScalingGroup
203 + Properties:
204 + HealthCheckType: ELB
205 + HealthCheckGracePeriod: 300
206 + MinSize:
207 + Ref: MinSize
208 + MaxSize:
209 + Ref: MaxSize
210 + LaunchConfigurationName:
211 + Ref: WebappLaunchConfig
212 + VPCZoneIdentifier:
213 + Ref: WebappSubnets
214 + TargetGroupARNs:
215 + - Ref: ALBTargetGroup
216 + Tags:
217 + - Key: Name
218 + Value: webapp-example
219 + PropagateAtLaunch: true
220 + ALBListener:
221 + Type: AWS::ElasticLoadBalancingV2::Listener
222 + Properties:
223 + DefaultActions:
224 + -
225 + Type: forward
226 + TargetGroupArn:
227 + Ref: ALBTargetGroup
228 + LoadBalancerArn:
229 + Ref: LoadBalancer
230 + Port: 80
231 + Protocol: HTTP
232 + LoadBalancer:
233 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
234 + Properties:
235 + Name: testLoadbalancer
236 + Scheme: internet-facing
237 + Subnets:
238 + Ref: ALBSubnets
239 + SecurityGroups:
240 + - Ref: ALBSecurityGroup
241 + Tags:
242 + - Key: Name
243 + Value:
244 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
245 + ALBTargetGroup:
246 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
247 + Properties:
248 + TargetGroupAttributes:
249 + - Key: deregistration_delay.timeout_seconds
250 + Value: 30
251 + HealthCheckIntervalSeconds: 30
252 + UnhealthyThresholdCount: 2
253 + HealthyThresholdCount: 2
254 + HealthCheckPath: /
255 + Port: 3000
256 + Protocol: HTTP
257 + VpcId:
258 + Ref: VPC
259 +Outputs:
260 + WebappUrl:
261 + Description: Webapp URL
262 + Value: !GetAtt LoadBalancer.DNSName
263 + DeploymentGroup:
264 + Description: Webapp Deployment Group
265 + Value: !Ref WebappDeploymentGroup
266 + DeploymentBucket:
267 + Description: Deployment bucket
268 + Value: !Ref WebappDeploymentBucket
269 + ApplicationName:
270 + Description: CodeDeploy Application name
271 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + -
143 + Effect: Allow
144 + Action:
145 + - autoscaling:*
146 + - cloudwatch:*
147 + - logs:*
148 + - sns:*
149 + Resource: "*"
150 + Policies:
151 + -
152 + PolicyName: "allow-webapp-deployment-bucket-bucket"
153 + PolicyDocument:
154 + Version: "2012-10-17"
155 + Statement:
156 + -
157 + Effect: "Allow"
158 + Action: "s3:getObject"
159 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
274 +
275 + [plugins]
276 +cwlogs = cwlogs
277 +[default]
278 +region = us-east-1
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 2
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
196 + sudo systemctl start awslogsd
197 + # get node into yum
198 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
199 + # install node and npm in one line
200 + yum install -y nodejs
201 + # install pm2 to restart node app
202 + npm i -g pm2@2.4.3
203 + AutoScalingGroup:
204 + Type: AWS::AutoScaling::AutoScalingGroup
205 + Properties:
206 + HealthCheckType: ELB
207 + HealthCheckGracePeriod: 300
208 + MinSize:
209 + Ref: MinSize
210 + MaxSize:
211 + Ref: MaxSize
212 + LaunchConfigurationName:
213 + Ref: WebappLaunchConfig
214 + VPCZoneIdentifier:
215 + Ref: WebappSubnets
216 + TargetGroupARNs:
217 + - Ref: ALBTargetGroup
218 + Tags:
219 + - Key: Name
220 + Value: webapp-example
221 + PropagateAtLaunch: true
222 + ALBListener:
223 + Type: AWS::ElasticLoadBalancingV2::Listener
224 + Properties:
225 + DefaultActions:
226 + -
227 + Type: forward
228 + TargetGroupArn:
229 + Ref: ALBTargetGroup
230 + LoadBalancerArn:
231 + Ref: LoadBalancer
232 + Port: 80
233 + Protocol: HTTP
234 + LoadBalancer:
235 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
236 + Properties:
237 + Name: testLoadbalancer
238 + Scheme: internet-facing
239 + Subnets:
240 + Ref: ALBSubnets
241 + SecurityGroups:
242 + - Ref: ALBSecurityGroup
243 + Tags:
244 + - Key: Name
245 + Value:
246 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
247 + ALBTargetGroup:
248 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
249 + Properties:
250 + TargetGroupAttributes:
251 + - Key: deregistration_delay.timeout_seconds
252 + Value: 30
253 + HealthCheckIntervalSeconds: 30
254 + UnhealthyThresholdCount: 2
255 + HealthyThresholdCount: 2
256 + HealthCheckPath: /
257 + Port: 3000
258 + Protocol: HTTP
259 + VpcId:
260 + Ref: VPC
261 +Outputs:
262 + WebappUrl:
263 + Description: Webapp URL
264 + Value: !GetAtt LoadBalancer.DNSName
265 + DeploymentGroup:
266 + Description: Webapp Deployment Group
267 + Value: !Ref WebappDeploymentGroup
268 + DeploymentBucket:
269 + Description: Deployment bucket
270 + Value: !Ref WebappDeploymentBucket
271 + ApplicationName:
272 + Description: CodeDeploy Application name
273 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo "[plugins]₩cwlogs = cwlogs₩n[default]₩nregion = ap-northeast-2" > test.txt
196 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
197 + sudo systemctl start awslogsd
198 + # get node into yum
199 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
200 + # install node and npm in one line
201 + yum install -y nodejs
202 + # install pm2 to restart node app
203 + npm i -g pm2@2.4.3
204 + AutoScalingGroup:
205 + Type: AWS::AutoScaling::AutoScalingGroup
206 + Properties:
207 + HealthCheckType: ELB
208 + HealthCheckGracePeriod: 300
209 + MinSize:
210 + Ref: MinSize
211 + MaxSize:
212 + Ref: MaxSize
213 + LaunchConfigurationName:
214 + Ref: WebappLaunchConfig
215 + VPCZoneIdentifier:
216 + Ref: WebappSubnets
217 + TargetGroupARNs:
218 + - Ref: ALBTargetGroup
219 + Tags:
220 + - Key: Name
221 + Value: webapp-example
222 + PropagateAtLaunch: true
223 + ALBListener:
224 + Type: AWS::ElasticLoadBalancingV2::Listener
225 + Properties:
226 + DefaultActions:
227 + -
228 + Type: forward
229 + TargetGroupArn:
230 + Ref: ALBTargetGroup
231 + LoadBalancerArn:
232 + Ref: LoadBalancer
233 + Port: 80
234 + Protocol: HTTP
235 + LoadBalancer:
236 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
237 + Properties:
238 + Name: testLoadbalancer
239 + Scheme: internet-facing
240 + Subnets:
241 + Ref: ALBSubnets
242 + SecurityGroups:
243 + - Ref: ALBSecurityGroup
244 + Tags:
245 + - Key: Name
246 + Value:
247 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
248 + ALBTargetGroup:
249 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
250 + Properties:
251 + TargetGroupAttributes:
252 + - Key: deregistration_delay.timeout_seconds
253 + Value: 30
254 + HealthCheckIntervalSeconds: 30
255 + UnhealthyThresholdCount: 2
256 + HealthyThresholdCount: 2
257 + HealthCheckPath: /
258 + Port: 3000
259 + Protocol: HTTP
260 + VpcId:
261 + Ref: VPC
262 +Outputs:
263 + WebappUrl:
264 + Description: Webapp URL
265 + Value: !GetAtt LoadBalancer.DNSName
266 + DeploymentGroup:
267 + Description: Webapp Deployment Group
268 + Value: !Ref WebappDeploymentGroup
269 + DeploymentBucket:
270 + Description: Deployment bucket
271 + Value: !Ref WebappDeploymentBucket
272 + ApplicationName:
273 + Description: CodeDeploy Application name
274 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo "[plugins]\ncwlogs = cwlogs\n[default]₩nregion = ap-northeast-2" > test.txt
196 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
197 + sudo systemctl start awslogsd
198 + # get node into yum
199 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
200 + # install node and npm in one line
201 + yum install -y nodejs
202 + # install pm2 to restart node app
203 + npm i -g pm2@2.4.3
204 + AutoScalingGroup:
205 + Type: AWS::AutoScaling::AutoScalingGroup
206 + Properties:
207 + HealthCheckType: ELB
208 + HealthCheckGracePeriod: 300
209 + MinSize:
210 + Ref: MinSize
211 + MaxSize:
212 + Ref: MaxSize
213 + LaunchConfigurationName:
214 + Ref: WebappLaunchConfig
215 + VPCZoneIdentifier:
216 + Ref: WebappSubnets
217 + TargetGroupARNs:
218 + - Ref: ALBTargetGroup
219 + Tags:
220 + - Key: Name
221 + Value: webapp-example
222 + PropagateAtLaunch: true
223 + ALBListener:
224 + Type: AWS::ElasticLoadBalancingV2::Listener
225 + Properties:
226 + DefaultActions:
227 + -
228 + Type: forward
229 + TargetGroupArn:
230 + Ref: ALBTargetGroup
231 + LoadBalancerArn:
232 + Ref: LoadBalancer
233 + Port: 80
234 + Protocol: HTTP
235 + LoadBalancer:
236 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
237 + Properties:
238 + Name: testLoadbalancer
239 + Scheme: internet-facing
240 + Subnets:
241 + Ref: ALBSubnets
242 + SecurityGroups:
243 + - Ref: ALBSecurityGroup
244 + Tags:
245 + - Key: Name
246 + Value:
247 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
248 + ALBTargetGroup:
249 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
250 + Properties:
251 + TargetGroupAttributes:
252 + - Key: deregistration_delay.timeout_seconds
253 + Value: 30
254 + HealthCheckIntervalSeconds: 30
255 + UnhealthyThresholdCount: 2
256 + HealthyThresholdCount: 2
257 + HealthCheckPath: /
258 + Port: 3000
259 + Protocol: HTTP
260 + VpcId:
261 + Ref: VPC
262 +Outputs:
263 + WebappUrl:
264 + Description: Webapp URL
265 + Value: !GetAtt LoadBalancer.DNSName
266 + DeploymentGroup:
267 + Description: Webapp Deployment Group
268 + Value: !Ref WebappDeploymentGroup
269 + DeploymentBucket:
270 + Description: Deployment bucket
271 + Value: !Ref WebappDeploymentBucket
272 + ApplicationName:
273 + Description: CodeDeploy Application name
274 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > test.txt
196 + sudo cp ./test.txt /etc/awslogs/awslogs.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo systemctl start awslogsd
199 + # get node into yum
200 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
201 + # install node and npm in one line
202 + yum install -y nodejs
203 + # install pm2 to restart node app
204 + npm i -g pm2@2.4.3
205 + AutoScalingGroup:
206 + Type: AWS::AutoScaling::AutoScalingGroup
207 + Properties:
208 + HealthCheckType: ELB
209 + HealthCheckGracePeriod: 300
210 + MinSize:
211 + Ref: MinSize
212 + MaxSize:
213 + Ref: MaxSize
214 + LaunchConfigurationName:
215 + Ref: WebappLaunchConfig
216 + VPCZoneIdentifier:
217 + Ref: WebappSubnets
218 + TargetGroupARNs:
219 + - Ref: ALBTargetGroup
220 + Tags:
221 + - Key: Name
222 + Value: webapp-example
223 + PropagateAtLaunch: true
224 + ALBListener:
225 + Type: AWS::ElasticLoadBalancingV2::Listener
226 + Properties:
227 + DefaultActions:
228 + -
229 + Type: forward
230 + TargetGroupArn:
231 + Ref: ALBTargetGroup
232 + LoadBalancerArn:
233 + Ref: LoadBalancer
234 + Port: 80
235 + Protocol: HTTP
236 + LoadBalancer:
237 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
238 + Properties:
239 + Name: testLoadbalancer
240 + Scheme: internet-facing
241 + Subnets:
242 + Ref: ALBSubnets
243 + SecurityGroups:
244 + - Ref: ALBSecurityGroup
245 + Tags:
246 + - Key: Name
247 + Value:
248 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
249 + ALBTargetGroup:
250 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
251 + Properties:
252 + TargetGroupAttributes:
253 + - Key: deregistration_delay.timeout_seconds
254 + Value: 30
255 + HealthCheckIntervalSeconds: 30
256 + UnhealthyThresholdCount: 2
257 + HealthyThresholdCount: 2
258 + HealthCheckPath: /
259 + Port: 3000
260 + Protocol: HTTP
261 + VpcId:
262 + Ref: VPC
263 +Outputs:
264 + WebappUrl:
265 + Description: Webapp URL
266 + Value: !GetAtt LoadBalancer.DNSName
267 + DeploymentGroup:
268 + Description: Webapp Deployment Group
269 + Value: !Ref WebappDeploymentGroup
270 + DeploymentBucket:
271 + Description: Deployment bucket
272 + Value: !Ref WebappDeploymentBucket
273 + ApplicationName:
274 + Description: CodeDeploy Application name
275 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > test.txt
196 + sudo cp ./test.txt /etc/awslogs/awscli.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo systemctl start awslogsd
199 + # get node into yum
200 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
201 + # install node and npm in one line
202 + yum install -y nodejs
203 + # install pm2 to restart node app
204 + npm i -g pm2@2.4.3
205 + AutoScalingGroup:
206 + Type: AWS::AutoScaling::AutoScalingGroup
207 + Properties:
208 + HealthCheckType: ELB
209 + HealthCheckGracePeriod: 300
210 + MinSize:
211 + Ref: MinSize
212 + MaxSize:
213 + Ref: MaxSize
214 + LaunchConfigurationName:
215 + Ref: WebappLaunchConfig
216 + VPCZoneIdentifier:
217 + Ref: WebappSubnets
218 + TargetGroupARNs:
219 + - Ref: ALBTargetGroup
220 + Tags:
221 + - Key: Name
222 + Value: webapp-example
223 + PropagateAtLaunch: true
224 + ALBListener:
225 + Type: AWS::ElasticLoadBalancingV2::Listener
226 + Properties:
227 + DefaultActions:
228 + -
229 + Type: forward
230 + TargetGroupArn:
231 + Ref: ALBTargetGroup
232 + LoadBalancerArn:
233 + Ref: LoadBalancer
234 + Port: 80
235 + Protocol: HTTP
236 + LoadBalancer:
237 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
238 + Properties:
239 + Name: testLoadbalancer
240 + Scheme: internet-facing
241 + Subnets:
242 + Ref: ALBSubnets
243 + SecurityGroups:
244 + - Ref: ALBSecurityGroup
245 + Tags:
246 + - Key: Name
247 + Value:
248 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
249 + ALBTargetGroup:
250 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
251 + Properties:
252 + TargetGroupAttributes:
253 + - Key: deregistration_delay.timeout_seconds
254 + Value: 30
255 + HealthCheckIntervalSeconds: 30
256 + UnhealthyThresholdCount: 2
257 + HealthyThresholdCount: 2
258 + HealthCheckPath: /
259 + Port: 3000
260 + Protocol: HTTP
261 + VpcId:
262 + Ref: VPC
263 +Outputs:
264 + WebappUrl:
265 + Description: Webapp URL
266 + Value: !GetAtt LoadBalancer.DNSName
267 + DeploymentGroup:
268 + Description: Webapp Deployment Group
269 + Value: !Ref WebappDeploymentGroup
270 + DeploymentBucket:
271 + Description: Deployment bucket
272 + Value: !Ref WebappDeploymentBucket
273 + ApplicationName:
274 + Description: CodeDeploy Application name
275 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > test.txt
197 + sudo cp ./test.txt /etc/awslogs/awscli.conf
198 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
199 + sudo systemctl start awslogsd
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > test.txt
197 + sudo cp ./test.txt /etc/awslogs/awscli.conf
198 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
199 + sudo systemctl start awslogsd
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
197 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
198 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
199 + sudo systemctl start awslogsd
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + wget https://s3.amazonaws.com/aws-codedeploy-us-east-1/cloudwatch/codedeploy_logs.conf
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
199 + sudo systemctl start awslogsd
200 + # get node into yum
201 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
202 + # install node and npm in one line
203 + yum install -y nodejs
204 + # install pm2 to restart node app
205 + npm i -g pm2@2.4.3
206 + AutoScalingGroup:
207 + Type: AWS::AutoScaling::AutoScalingGroup
208 + Properties:
209 + HealthCheckType: ELB
210 + HealthCheckGracePeriod: 300
211 + MinSize:
212 + Ref: MinSize
213 + MaxSize:
214 + Ref: MaxSize
215 + LaunchConfigurationName:
216 + Ref: WebappLaunchConfig
217 + VPCZoneIdentifier:
218 + Ref: WebappSubnets
219 + TargetGroupARNs:
220 + - Ref: ALBTargetGroup
221 + Tags:
222 + - Key: Name
223 + Value: webapp-example
224 + PropagateAtLaunch: true
225 + ALBListener:
226 + Type: AWS::ElasticLoadBalancingV2::Listener
227 + Properties:
228 + DefaultActions:
229 + -
230 + Type: forward
231 + TargetGroupArn:
232 + Ref: ALBTargetGroup
233 + LoadBalancerArn:
234 + Ref: LoadBalancer
235 + Port: 80
236 + Protocol: HTTP
237 + LoadBalancer:
238 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
239 + Properties:
240 + Name: testLoadbalancer
241 + Scheme: internet-facing
242 + Subnets:
243 + Ref: ALBSubnets
244 + SecurityGroups:
245 + - Ref: ALBSecurityGroup
246 + Tags:
247 + - Key: Name
248 + Value:
249 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
250 + ALBTargetGroup:
251 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
252 + Properties:
253 + TargetGroupAttributes:
254 + - Key: deregistration_delay.timeout_seconds
255 + Value: 30
256 + HealthCheckIntervalSeconds: 30
257 + UnhealthyThresholdCount: 2
258 + HealthyThresholdCount: 2
259 + HealthCheckPath: /
260 + Port: 3000
261 + Protocol: HTTP
262 + VpcId:
263 + Ref: VPC
264 +Outputs:
265 + WebappUrl:
266 + Description: Webapp URL
267 + Value: !GetAtt LoadBalancer.DNSName
268 + DeploymentGroup:
269 + Description: Webapp Deployment Group
270 + Value: !Ref WebappDeploymentGroup
271 + DeploymentBucket:
272 + Description: Deployment bucket
273 + Value: !Ref WebappDeploymentBucket
274 + ApplicationName:
275 + Description: CodeDeploy Application name
276 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # shoud region change
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # cloudwatch
193 + sudo yum install -y awslogs
194 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
195 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
196 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
197 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
198 + sudo systemctl start awslogsd
199 + # get node into yum
200 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
201 + # install node and npm in one line
202 + yum install -y nodejs
203 + # install pm2 to restart node app
204 + npm i -g pm2@2.4.3
205 + AutoScalingGroup:
206 + Type: AWS::AutoScaling::AutoScalingGroup
207 + Properties:
208 + HealthCheckType: ELB
209 + HealthCheckGracePeriod: 300
210 + MinSize:
211 + Ref: MinSize
212 + MaxSize:
213 + Ref: MaxSize
214 + LaunchConfigurationName:
215 + Ref: WebappLaunchConfig
216 + VPCZoneIdentifier:
217 + Ref: WebappSubnets
218 + TargetGroupARNs:
219 + - Ref: ALBTargetGroup
220 + Tags:
221 + - Key: Name
222 + Value: webapp-example
223 + PropagateAtLaunch: true
224 + ALBListener:
225 + Type: AWS::ElasticLoadBalancingV2::Listener
226 + Properties:
227 + DefaultActions:
228 + -
229 + Type: forward
230 + TargetGroupArn:
231 + Ref: ALBTargetGroup
232 + LoadBalancerArn:
233 + Ref: LoadBalancer
234 + Port: 80
235 + Protocol: HTTP
236 + LoadBalancer:
237 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
238 + Properties:
239 + Name: testLoadbalancer
240 + Scheme: internet-facing
241 + Subnets:
242 + Ref: ALBSubnets
243 + SecurityGroups:
244 + - Ref: ALBSecurityGroup
245 + Tags:
246 + - Key: Name
247 + Value:
248 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
249 + ALBTargetGroup:
250 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
251 + Properties:
252 + TargetGroupAttributes:
253 + - Key: deregistration_delay.timeout_seconds
254 + Value: 30
255 + HealthCheckIntervalSeconds: 30
256 + UnhealthyThresholdCount: 2
257 + HealthyThresholdCount: 2
258 + HealthCheckPath: /
259 + Port: 3000
260 + Protocol: HTTP
261 + VpcId:
262 + Ref: VPC
263 +Outputs:
264 + WebappUrl:
265 + Description: Webapp URL
266 + Value: !GetAtt LoadBalancer.DNSName
267 + DeploymentGroup:
268 + Description: Webapp Deployment Group
269 + Value: !Ref WebappDeploymentGroup
270 + DeploymentBucket:
271 + Description: Deployment bucket
272 + Value: !Ref WebappDeploymentBucket
273 + ApplicationName:
274 + Description: CodeDeploy Application name
275 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + WebappApplication:
32 + Type: "AWS::CodeDeploy::Application"
33 + Properties:
34 + ApplicationName: testApp
35 + WebappDeploymentGroup:
36 + Type: "AWS::CodeDeploy::DeploymentGroup"
37 + Properties:
38 + DeploymentGroupName: test-group
39 + ApplicationName: !Ref WebappApplication
40 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
41 + DeploymentConfigName: CodeDeployDefault.OneAtATime
42 + DeploymentStyle:
43 + DeploymentType: IN_PLACE
44 + DeploymentOption: WITH_TRAFFIC_CONTROL
45 + LoadBalancerInfo:
46 + TargetGroupInfoList:
47 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
48 + AutoScalingGroups:
49 + - Ref: AutoScalingGroup
50 + ALBSecurityGroup:
51 + Type: AWS::EC2::SecurityGroup
52 + Properties:
53 + GroupDescription: allow access to ALB from internet
54 + VpcId:
55 + Ref: VPC
56 + SecurityGroupIngress:
57 + - IpProtocol: tcp
58 + FromPort: '80'
59 + ToPort: '80'
60 + CidrIp: 0.0.0.0/0
61 + WebappSecurityGroup:
62 + Type: AWS::EC2::SecurityGroup
63 + Properties:
64 + GroupDescription: allow access to Webapp from ALB
65 + VpcId:
66 + Ref: VPC
67 + SecurityGroupIngress:
68 + - IpProtocol: tcp
69 + FromPort: '3000'
70 + ToPort: '3000'
71 + SourceSecurityGroupId:
72 + Ref: ALBSecurityGroup
73 + - IpProtocol: tcp
74 + FromPort: '22'
75 + ToPort: '22'
76 + CidrIp: 0.0.0.0/0
77 + WebappDeploymentBucket:
78 + Type: "AWS::S3::Bucket"
79 + Properties:
80 + BucketName: 'testtest11324'
81 + CodeDeployRole:
82 + Type: "AWS::IAM::Role"
83 + Properties:
84 + AssumeRolePolicyDocument:
85 + Version: "2012-10-17"
86 + Statement:
87 + -
88 + Effect: "Allow"
89 + Principal:
90 + Service:
91 + - "codedeploy.amazonaws.com"
92 + Action:
93 + - "sts:AssumeRole"
94 + Policies:
95 + -
96 + PolicyName: allow-autoscaling
97 + PolicyDocument:
98 + Version: "2012-10-17"
99 + Statement:
100 + -
101 + Effect: Allow
102 + Action:
103 + - ec2:*
104 + - autoscaling:*
105 + Resource: "*"
106 + -
107 + PolicyName: allow-loadbalance
108 + PolicyDocument:
109 + Version: "2012-10-17"
110 + Statement:
111 + -
112 + Effect: Allow
113 + Action:
114 + - ec2:*
115 + - autoscaling:*
116 + Resource: "*"
117 + -
118 + Effect: Allow
119 + Action:
120 + - iam:CreateServiceLinkedRole
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - elasticloadbalancing:*
126 + Resource: "*"
127 + WebappRole:
128 + Type: "AWS::IAM::Role"
129 + Properties:
130 + AssumeRolePolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Principal:
136 + Service:
137 + - "ec2.amazonaws.com"
138 + - "codedeploy.amazonaws.com"
139 + - "events.amazonaws.com"
140 + Action:
141 + - "sts:AssumeRole"
142 + Policies:
143 + -
144 + PolicyName: "allow-webapp-deployment-bucket-bucket"
145 + PolicyDocument:
146 + Version: "2012-10-17"
147 + Statement:
148 + -
149 + Effect: "Allow"
150 + Action: "s3:getObject"
151 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
152 + -
153 + Effect: Allow
154 + Action:
155 + - autoscaling:*
156 + - cloudwatch:*
157 + - logs:*
158 + - sns:*
159 + Resource: "*"
160 + WebappInstanceProfile:
161 + Type: "AWS::IAM::InstanceProfile"
162 + Properties:
163 + Roles:
164 + - Ref: WebappRole
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # you have to notice region in url
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # install cloudwatch logs agent
193 + sudo yum install -y awslogs
194 + # set config file sending log to right region
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
199 + # start cloudwatch agent
200 + sudo systemctl start awslogsd
201 + # get node into yum
202 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
203 + # install node and npm in one line
204 + yum install -y nodejs
205 + # install pm2 to restart node app
206 + npm i -g pm2@2.4.3
207 + AutoScalingGroup:
208 + Type: AWS::AutoScaling::AutoScalingGroup
209 + Properties:
210 + HealthCheckType: ELB
211 + HealthCheckGracePeriod: 300
212 + MinSize:
213 + Ref: MinSize
214 + MaxSize:
215 + Ref: MaxSize
216 + LaunchConfigurationName:
217 + Ref: WebappLaunchConfig
218 + VPCZoneIdentifier:
219 + Ref: WebappSubnets
220 + TargetGroupARNs:
221 + - Ref: ALBTargetGroup
222 + Tags:
223 + - Key: Name
224 + Value: webapp-example
225 + PropagateAtLaunch: true
226 + ALBListener:
227 + Type: AWS::ElasticLoadBalancingV2::Listener
228 + Properties:
229 + DefaultActions:
230 + -
231 + Type: forward
232 + TargetGroupArn:
233 + Ref: ALBTargetGroup
234 + LoadBalancerArn:
235 + Ref: LoadBalancer
236 + Port: 80
237 + Protocol: HTTP
238 + LoadBalancer:
239 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
240 + Properties:
241 + Name: testLoadbalancer
242 + Scheme: internet-facing
243 + Subnets:
244 + Ref: ALBSubnets
245 + SecurityGroups:
246 + - Ref: ALBSecurityGroup
247 + Tags:
248 + - Key: Name
249 + Value:
250 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
251 + ALBTargetGroup:
252 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
253 + Properties:
254 + TargetGroupAttributes:
255 + - Key: deregistration_delay.timeout_seconds
256 + Value: 30
257 + HealthCheckIntervalSeconds: 30
258 + UnhealthyThresholdCount: 2
259 + HealthyThresholdCount: 2
260 + HealthCheckPath: /
261 + Port: 3000
262 + Protocol: HTTP
263 + VpcId:
264 + Ref: VPC
265 +Outputs:
266 + WebappUrl:
267 + Description: Webapp URL
268 + Value: !GetAtt LoadBalancer.DNSName
269 + DeploymentGroup:
270 + Description: Webapp Deployment Group
271 + Value: !Ref WebappDeploymentGroup
272 + DeploymentBucket:
273 + Description: Deployment bucket
274 + Value: !Ref WebappDeploymentBucket
275 + ApplicationName:
276 + Description: CodeDeploy Application name
277 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + CodeDeployRole:
32 + Type: "AWS::IAM::Role"
33 + Properties:
34 + AssumeRolePolicyDocument:
35 + Version: "2012-10-17"
36 + Statement:
37 + -
38 + Effect: "Allow"
39 + Principal:
40 + Service:
41 + - "codedeploy.amazonaws.com"
42 + Action:
43 + - "sts:AssumeRole"
44 + Policies:
45 + -
46 + PolicyName: allow-autoscaling
47 + PolicyDocument:
48 + Version: "2012-10-17"
49 + Statement:
50 + -
51 + Effect: Allow
52 + Action:
53 + - ec2:*
54 + - autoscaling:*
55 + Resource: "*"
56 + -
57 + PolicyName: allow-loadbalance
58 + PolicyDocument:
59 + Version: "2012-10-17"
60 + Statement:
61 + -
62 + Effect: Allow
63 + Action:
64 + - ec2:*
65 + - autoscaling:*
66 + Resource: "*"
67 + -
68 + Effect: Allow
69 + Action:
70 + - iam:CreateServiceLinkedRole
71 + Resource: "*"
72 + -
73 + Effect: Allow
74 + Action:
75 + - elasticloadbalancing:*
76 + Resource: "*"
77 + WebappRole:
78 + Type: "AWS::IAM::Role"
79 + Properties:
80 + AssumeRolePolicyDocument:
81 + Version: "2012-10-17"
82 + Statement:
83 + -
84 + Effect: "Allow"
85 + Principal:
86 + Service:
87 + - "ec2.amazonaws.com"
88 + - "codedeploy.amazonaws.com"
89 + - "events.amazonaws.com"
90 + Action:
91 + - "sts:AssumeRole"
92 + Policies:
93 + -
94 + PolicyName: "allow-webapp-deployment-bucket-bucket"
95 + PolicyDocument:
96 + Version: "2012-10-17"
97 + Statement:
98 + -
99 + Effect: "Allow"
100 + Action: "s3:getObject"
101 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
102 + -
103 + Effect: Allow
104 + Action:
105 + - autoscaling:*
106 + - cloudwatch:*
107 + - logs:*
108 + - sns:*
109 + Resource: "*"
110 + WebappInstanceProfile:
111 + Type: "AWS::IAM::InstanceProfile"
112 + Properties:
113 + Roles:
114 + - Ref: WebappRole
115 + WebappApplication:
116 + Type: "AWS::CodeDeploy::Application"
117 + Properties:
118 + ApplicationName: testApp
119 + WebappDeploymentGroup:
120 + Type: "AWS::CodeDeploy::DeploymentGroup"
121 + Properties:
122 + DeploymentGroupName: test-group
123 + ApplicationName: !Ref WebappApplication
124 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
125 + DeploymentConfigName: CodeDeployDefault.OneAtATime
126 + DeploymentStyle:
127 + DeploymentType: IN_PLACE
128 + DeploymentOption: WITH_TRAFFIC_CONTROL
129 + LoadBalancerInfo:
130 + TargetGroupInfoList:
131 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
132 + AutoScalingGroups:
133 + - Ref: AutoScalingGroup
134 + ALBSecurityGroup:
135 + Type: AWS::EC2::SecurityGroup
136 + Properties:
137 + GroupDescription: allow access to ALB from internet
138 + VpcId:
139 + Ref: VPC
140 + SecurityGroupIngress:
141 + - IpProtocol: tcp
142 + FromPort: '80'
143 + ToPort: '80'
144 + CidrIp: 0.0.0.0/0
145 + WebappSecurityGroup:
146 + Type: AWS::EC2::SecurityGroup
147 + Properties:
148 + GroupDescription: allow access to Webapp from ALB
149 + VpcId:
150 + Ref: VPC
151 + SecurityGroupIngress:
152 + - IpProtocol: tcp
153 + FromPort: '3000'
154 + ToPort: '3000'
155 + SourceSecurityGroupId:
156 + Ref: ALBSecurityGroup
157 + - IpProtocol: tcp
158 + FromPort: '22'
159 + ToPort: '22'
160 + CidrIp: 0.0.0.0/0
161 + WebappDeploymentBucket:
162 + Type: "AWS::S3::Bucket"
163 + Properties:
164 + BucketName: 'testtest11324'
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # you have to notice region in url
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # install cloudwatch logs agent
193 + sudo yum install -y awslogs
194 + # set config file sending log to right region
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
199 + # start cloudwatch agent
200 + sudo systemctl start awslogsd
201 + # get node into yum
202 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
203 + # install node and npm in one line
204 + yum install -y nodejs
205 + # install pm2 to restart node app
206 + npm i -g pm2@2.4.3
207 + AutoScalingGroup:
208 + Type: AWS::AutoScaling::AutoScalingGroup
209 + Properties:
210 + HealthCheckType: ELB
211 + HealthCheckGracePeriod: 300
212 + MinSize:
213 + Ref: MinSize
214 + MaxSize:
215 + Ref: MaxSize
216 + LaunchConfigurationName:
217 + Ref: WebappLaunchConfig
218 + VPCZoneIdentifier:
219 + Ref: WebappSubnets
220 + TargetGroupARNs:
221 + - Ref: ALBTargetGroup
222 + Tags:
223 + - Key: Name
224 + Value: webapp-example
225 + PropagateAtLaunch: true
226 + ALBListener:
227 + Type: AWS::ElasticLoadBalancingV2::Listener
228 + Properties:
229 + DefaultActions:
230 + -
231 + Type: forward
232 + TargetGroupArn:
233 + Ref: ALBTargetGroup
234 + LoadBalancerArn:
235 + Ref: LoadBalancer
236 + Port: 80
237 + Protocol: HTTP
238 + LoadBalancer:
239 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
240 + Properties:
241 + Name: testLoadbalancer
242 + Scheme: internet-facing
243 + Subnets:
244 + Ref: ALBSubnets
245 + SecurityGroups:
246 + - Ref: ALBSecurityGroup
247 + Tags:
248 + - Key: Name
249 + Value:
250 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
251 + ALBTargetGroup:
252 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
253 + Properties:
254 + TargetGroupAttributes:
255 + - Key: deregistration_delay.timeout_seconds
256 + Value: 30
257 + HealthCheckIntervalSeconds: 30
258 + UnhealthyThresholdCount: 2
259 + HealthyThresholdCount: 2
260 + HealthCheckPath: /
261 + Port: 3000
262 + Protocol: HTTP
263 + VpcId:
264 + Ref: VPC
265 +Outputs:
266 + WebappUrl:
267 + Description: Webapp URL
268 + Value: !GetAtt LoadBalancer.DNSName
269 + DeploymentGroup:
270 + Description: Webapp Deployment Group
271 + Value: !Ref WebappDeploymentGroup
272 + DeploymentBucket:
273 + Description: Deployment bucket
274 + Value: !Ref WebappDeploymentBucket
275 + ApplicationName:
276 + Description: CodeDeploy Application name
277 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + CodeDeployRole:
32 + Type: "AWS::IAM::Role"
33 + Properties:
34 + AssumeRolePolicyDocument:
35 + Version: "2012-10-17"
36 + Statement:
37 + -
38 + Effect: "Allow"
39 + Principal:
40 + Service:
41 + - "codedeploy.amazonaws.com"
42 + Action:
43 + - "sts:AssumeRole"
44 + Policies:
45 + -
46 + PolicyName: allow-autoscaling
47 + PolicyDocument:
48 + Version: "2012-10-17"
49 + Statement:
50 + -
51 + Effect: Allow
52 + Action:
53 + - ec2:*
54 + - autoscaling:*
55 + Resource: "*"
56 + -
57 + PolicyName: allow-loadbalance
58 + PolicyDocument:
59 + Version: "2012-10-17"
60 + Statement:
61 + -
62 + Effect: Allow
63 + Action:
64 + - ec2:*
65 + - autoscaling:*
66 + Resource: "*"
67 + -
68 + Effect: Allow
69 + Action:
70 + - iam:CreateServiceLinkedRole
71 + Resource: "*"
72 + -
73 + Effect: Allow
74 + Action:
75 + - elasticloadbalancing:*
76 + Resource: "*"
77 + WebappRole:
78 + Type: "AWS::IAM::Role"
79 + Properties:
80 + AssumeRolePolicyDocument:
81 + Version: "2012-10-17"
82 + Statement:
83 + -
84 + Effect: "Allow"
85 + Principal:
86 + Service:
87 + - "ec2.amazonaws.com"
88 + - "codedeploy.amazonaws.com"
89 + - "events.amazonaws.com"
90 + Action:
91 + - "sts:AssumeRole"
92 + Policies:
93 + -
94 + PolicyName: "allow-webapp-deployment-bucket-bucket"
95 + PolicyDocument:
96 + Version: "2012-10-17"
97 + Statement:
98 + -
99 + Effect: "Allow"
100 + Action: "s3:getObject"
101 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
102 + -
103 + Effect: Allow
104 + Action:
105 + - autoscaling:*
106 + - cloudwatch:*
107 + - logs:*
108 + - sns:*
109 + Resource: "*"
110 + WebappInstanceProfile:
111 + Type: "AWS::IAM::InstanceProfile"
112 + Properties:
113 + Roles:
114 + - Ref: WebappRole
115 + ALBSecurityGroup:
116 + Type: AWS::EC2::SecurityGroup
117 + Properties:
118 + GroupDescription: allow access to ALB from internet
119 + VpcId:
120 + Ref: VPC
121 + SecurityGroupIngress:
122 + - IpProtocol: tcp
123 + FromPort: '80'
124 + ToPort: '80'
125 + CidrIp: 0.0.0.0/0
126 + WebappSecurityGroup:
127 + Type: AWS::EC2::SecurityGroup
128 + Properties:
129 + GroupDescription: allow access to Webapp from ALB
130 + VpcId:
131 + Ref: VPC
132 + SecurityGroupIngress:
133 + - IpProtocol: tcp
134 + FromPort: '3000'
135 + ToPort: '3000'
136 + SourceSecurityGroupId:
137 + Ref: ALBSecurityGroup
138 + - IpProtocol: tcp
139 + FromPort: '22'
140 + ToPort: '22'
141 + CidrIp: 0.0.0.0/0
142 + WebappDeploymentBucket:
143 + Type: "AWS::S3::Bucket"
144 + Properties:
145 + BucketName: 'testtest11324'
146 + WebappApplication:
147 + Type: "AWS::CodeDeploy::Application"
148 + Properties:
149 + ApplicationName: testApp
150 + WebappDeploymentGroup:
151 + Type: "AWS::CodeDeploy::DeploymentGroup"
152 + Properties:
153 + DeploymentGroupName: test-group
154 + ApplicationName: !Ref WebappApplication
155 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
156 + DeploymentConfigName: CodeDeployDefault.OneAtATime
157 + DeploymentStyle:
158 + DeploymentType: IN_PLACE
159 + DeploymentOption: WITH_TRAFFIC_CONTROL
160 + LoadBalancerInfo:
161 + TargetGroupInfoList:
162 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
163 + AutoScalingGroups:
164 + - Ref: AutoScalingGroup
165 + WebappLaunchConfig:
166 + Type: AWS::AutoScaling::LaunchConfiguration
167 + Properties:
168 + AssociatePublicIpAddress: true
169 + ImageId:
170 + Ref: AMIID
171 + InstanceType: t2.micro
172 + KeyName:
173 + Ref: KeyName
174 + SecurityGroups:
175 + - Ref: WebappSecurityGroup
176 + IamInstanceProfile:
177 + Ref: WebappInstanceProfile
178 + UserData:
179 + Fn::Base64:
180 + !Sub |
181 + #! /bin/bash -xe
182 + # update yum just in case
183 + yum update -y
184 + # install codedeploy agent
185 + yum install -y ruby
186 + yum install -y wget
187 + cd /home/ec2-user
188 + # you have to notice region in url
189 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
190 + chmod +x ./install
191 + ./install auto
192 + # install cloudwatch logs agent
193 + sudo yum install -y awslogs
194 + # set config file sending log to right region
195 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
196 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
197 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
198 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
199 + # start cloudwatch agent
200 + sudo systemctl start awslogsd
201 + # get node into yum
202 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
203 + # install node and npm in one line
204 + yum install -y nodejs
205 + # install pm2 to restart node app
206 + npm i -g pm2@2.4.3
207 + AutoScalingGroup:
208 + Type: AWS::AutoScaling::AutoScalingGroup
209 + Properties:
210 + HealthCheckType: ELB
211 + HealthCheckGracePeriod: 300
212 + MinSize:
213 + Ref: MinSize
214 + MaxSize:
215 + Ref: MaxSize
216 + LaunchConfigurationName:
217 + Ref: WebappLaunchConfig
218 + VPCZoneIdentifier:
219 + Ref: WebappSubnets
220 + TargetGroupARNs:
221 + - Ref: ALBTargetGroup
222 + Tags:
223 + - Key: Name
224 + Value: webapp-example
225 + PropagateAtLaunch: true
226 + ALBListener:
227 + Type: AWS::ElasticLoadBalancingV2::Listener
228 + Properties:
229 + DefaultActions:
230 + -
231 + Type: forward
232 + TargetGroupArn:
233 + Ref: ALBTargetGroup
234 + LoadBalancerArn:
235 + Ref: LoadBalancer
236 + Port: 80
237 + Protocol: HTTP
238 + LoadBalancer:
239 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
240 + Properties:
241 + Name: testLoadbalancer
242 + Scheme: internet-facing
243 + Subnets:
244 + Ref: ALBSubnets
245 + SecurityGroups:
246 + - Ref: ALBSecurityGroup
247 + Tags:
248 + - Key: Name
249 + Value:
250 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
251 + ALBTargetGroup:
252 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
253 + Properties:
254 + TargetGroupAttributes:
255 + - Key: deregistration_delay.timeout_seconds
256 + Value: 30
257 + HealthCheckIntervalSeconds: 30
258 + UnhealthyThresholdCount: 2
259 + HealthyThresholdCount: 2
260 + HealthCheckPath: /
261 + Port: 3000
262 + Protocol: HTTP
263 + VpcId:
264 + Ref: VPC
265 +Outputs:
266 + WebappUrl:
267 + Description: Webapp URL
268 + Value: !GetAtt LoadBalancer.DNSName
269 + DeploymentGroup:
270 + Description: Webapp Deployment Group
271 + Value: !Ref WebappDeploymentGroup
272 + DeploymentBucket:
273 + Description: Deployment bucket
274 + Value: !Ref WebappDeploymentBucket
275 + ApplicationName:
276 + Description: CodeDeploy Application name
277 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + CodeDeployRole:
32 + Type: "AWS::IAM::Role"
33 + Properties:
34 + AssumeRolePolicyDocument:
35 + Version: "2012-10-17"
36 + Statement:
37 + -
38 + Effect: "Allow"
39 + Principal:
40 + Service:
41 + - "codedeploy.amazonaws.com"
42 + Action:
43 + - "sts:AssumeRole"
44 + Policies:
45 + -
46 + PolicyName: allow-autoscaling
47 + PolicyDocument:
48 + Version: "2012-10-17"
49 + Statement:
50 + -
51 + Effect: Allow
52 + Action:
53 + - ec2:*
54 + - autoscaling:*
55 + Resource: "*"
56 + -
57 + PolicyName: allow-loadbalance
58 + PolicyDocument:
59 + Version: "2012-10-17"
60 + Statement:
61 + -
62 + Effect: Allow
63 + Action:
64 + - ec2:*
65 + - autoscaling:*
66 + Resource: "*"
67 + -
68 + Effect: Allow
69 + Action:
70 + - iam:CreateServiceLinkedRole
71 + Resource: "*"
72 + -
73 + Effect: Allow
74 + Action:
75 + - elasticloadbalancing:*
76 + Resource: "*"
77 + WebappRole:
78 + Type: "AWS::IAM::Role"
79 + Properties:
80 + AssumeRolePolicyDocument:
81 + Version: "2012-10-17"
82 + Statement:
83 + -
84 + Effect: "Allow"
85 + Principal:
86 + Service:
87 + - "ec2.amazonaws.com"
88 + - "codedeploy.amazonaws.com"
89 + - "events.amazonaws.com"
90 + Action:
91 + - "sts:AssumeRole"
92 + Policies:
93 + -
94 + PolicyName: "allow-webapp-deployment-bucket-bucket"
95 + PolicyDocument:
96 + Version: "2012-10-17"
97 + Statement:
98 + -
99 + Effect: "Allow"
100 + Action: "s3:getObject"
101 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
102 + -
103 + Effect: Allow
104 + Action:
105 + - autoscaling:*
106 + - cloudwatch:*
107 + - logs:*
108 + - sns:*
109 + Resource: "*"
110 + WebappInstanceProfile:
111 + Type: "AWS::IAM::InstanceProfile"
112 + Properties:
113 + Roles:
114 + - Ref: WebappRole
115 + ALBSecurityGroup:
116 + Type: AWS::EC2::SecurityGroup
117 + Properties:
118 + GroupDescription: allow access to ALB from internet
119 + VpcId:
120 + Ref: VPC
121 + SecurityGroupIngress:
122 + - IpProtocol: tcp
123 + FromPort: '80'
124 + ToPort: '80'
125 + CidrIp: 0.0.0.0/0
126 + WebappSecurityGroup:
127 + Type: AWS::EC2::SecurityGroup
128 + Properties:
129 + GroupDescription: allow access to Webapp from ALB
130 + VpcId:
131 + Ref: VPC
132 + SecurityGroupIngress:
133 + - IpProtocol: tcp
134 + FromPort: '3000'
135 + ToPort: '3000'
136 + SourceSecurityGroupId:
137 + Ref: ALBSecurityGroup
138 + - IpProtocol: tcp
139 + FromPort: '22'
140 + ToPort: '22'
141 + CidrIp: 0.0.0.0/0
142 + WebappDeploymentBucket:
143 + Type: "AWS::S3::Bucket"
144 + Properties:
145 + BucketName: 'testtest11324'
146 + WebappLaunchConfig:
147 + Type: AWS::AutoScaling::LaunchConfiguration
148 + Properties:
149 + AssociatePublicIpAddress: true
150 + ImageId:
151 + Ref: AMIID
152 + InstanceType: t2.micro
153 + KeyName:
154 + Ref: KeyName
155 + SecurityGroups:
156 + - Ref: WebappSecurityGroup
157 + IamInstanceProfile:
158 + Ref: WebappInstanceProfile
159 + UserData:
160 + Fn::Base64:
161 + !Sub |
162 + #! /bin/bash -xe
163 + # update yum just in case
164 + yum update -y
165 + # install codedeploy agent
166 + yum install -y ruby
167 + yum install -y wget
168 + cd /home/ec2-user
169 + # you have to notice region in url
170 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
171 + chmod +x ./install
172 + ./install auto
173 + # install cloudwatch logs agent
174 + sudo yum install -y awslogs
175 + # set config file sending log to right region
176 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
177 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
178 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
179 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
180 + # start cloudwatch agent
181 + sudo systemctl start awslogsd
182 + # get node into yum
183 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
184 + # install node and npm in one line
185 + yum install -y nodejs
186 + # install pm2 to restart node app
187 + npm i -g pm2@2.4.3
188 + AutoScalingGroup:
189 + Type: AWS::AutoScaling::AutoScalingGroup
190 + Properties:
191 + HealthCheckType: ELB
192 + HealthCheckGracePeriod: 300
193 + MinSize:
194 + Ref: MinSize
195 + MaxSize:
196 + Ref: MaxSize
197 + LaunchConfigurationName:
198 + Ref: WebappLaunchConfig
199 + VPCZoneIdentifier:
200 + Ref: WebappSubnets
201 + TargetGroupARNs:
202 + - Ref: ALBTargetGroup
203 + Tags:
204 + - Key: Name
205 + Value: webapp-example
206 + PropagateAtLaunch: true
207 + ALBListener:
208 + Type: AWS::ElasticLoadBalancingV2::Listener
209 + Properties:
210 + DefaultActions:
211 + -
212 + Type: forward
213 + TargetGroupArn:
214 + Ref: ALBTargetGroup
215 + LoadBalancerArn:
216 + Ref: LoadBalancer
217 + Port: 80
218 + Protocol: HTTP
219 + LoadBalancer:
220 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
221 + Properties:
222 + Name: testLoadbalancer
223 + Scheme: internet-facing
224 + Subnets:
225 + Ref: ALBSubnets
226 + SecurityGroups:
227 + - Ref: ALBSecurityGroup
228 + Tags:
229 + - Key: Name
230 + Value:
231 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
232 + ALBTargetGroup:
233 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
234 + Properties:
235 + TargetGroupAttributes:
236 + - Key: deregistration_delay.timeout_seconds
237 + Value: 30
238 + HealthCheckIntervalSeconds: 30
239 + UnhealthyThresholdCount: 2
240 + HealthyThresholdCount: 2
241 + HealthCheckPath: /
242 + Port: 3000
243 + Protocol: HTTP
244 + VpcId:
245 + Ref: VPC
246 + WebappApplication:
247 + Type: "AWS::CodeDeploy::Application"
248 + Properties:
249 + ApplicationName: testApp
250 + WebappDeploymentGroup:
251 + Type: "AWS::CodeDeploy::DeploymentGroup"
252 + Properties:
253 + DeploymentGroupName: test-group
254 + ApplicationName: !Ref WebappApplication
255 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
256 + DeploymentConfigName: CodeDeployDefault.OneAtATime
257 + DeploymentStyle:
258 + DeploymentType: IN_PLACE
259 + DeploymentOption: WITH_TRAFFIC_CONTROL
260 + LoadBalancerInfo:
261 + TargetGroupInfoList:
262 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
263 + AutoScalingGroups:
264 + - Ref: AutoScalingGroup
265 +Outputs:
266 + WebappUrl:
267 + Description: Webapp URL
268 + Value: !GetAtt LoadBalancer.DNSName
269 + DeploymentGroup:
270 + Description: Webapp Deployment Group
271 + Value: !Ref WebappDeploymentGroup
272 + DeploymentBucket:
273 + Description: Deployment bucket
274 + Value: !Ref WebappDeploymentBucket
275 + ApplicationName:
276 + Description: CodeDeploy Application name
277 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + KeyName:
3 + Type: String
4 + Default: dd
5 + WebappSubnets:
6 + Type: CommaDelimitedList
7 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
8 + ALBSubnets:
9 + Type: CommaDelimitedList
10 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
11 + MinSize:
12 + Type: Number
13 + Default: 2
14 + MaxSize:
15 + Type: Number
16 + Default: 3
17 + VPC:
18 + Type: String
19 + Default: vpc-aab1aac2
20 + AMIID:
21 + Type: String
22 + Default: ami-08ab3f7e72215fe91
23 + NamePrefix:
24 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
25 + Default: bluegreen
26 + Description: Prefix for resource tags made by this template (2-15 chars).
27 + MaxLength: 15
28 + MinLength: 2
29 + Type: String
30 +Resources:
31 + CodeDeployRole:
32 + Type: "AWS::IAM::Role"
33 + Properties:
34 + AssumeRolePolicyDocument:
35 + Version: "2012-10-17"
36 + Statement:
37 + -
38 + Effect: "Allow"
39 + Principal:
40 + Service:
41 + - "codedeploy.amazonaws.com"
42 + Action:
43 + - "sts:AssumeRole"
44 + Policies:
45 + -
46 + PolicyName: allow-autoscaling
47 + PolicyDocument:
48 + Version: "2012-10-17"
49 + Statement:
50 + -
51 + Effect: Allow
52 + Action:
53 + - ec2:*
54 + - autoscaling:*
55 + Resource: "*"
56 + -
57 + PolicyName: allow-loadbalance
58 + PolicyDocument:
59 + Version: "2012-10-17"
60 + Statement:
61 + -
62 + Effect: Allow
63 + Action:
64 + - ec2:*
65 + - autoscaling:*
66 + Resource: "*"
67 + -
68 + Effect: Allow
69 + Action:
70 + - iam:CreateServiceLinkedRole
71 + Resource: "*"
72 + -
73 + Effect: Allow
74 + Action:
75 + - elasticloadbalancing:*
76 + Resource: "*"
77 + WebappRole:
78 + Type: "AWS::IAM::Role"
79 + Properties:
80 + AssumeRolePolicyDocument:
81 + Version: "2012-10-17"
82 + Statement:
83 + -
84 + Effect: "Allow"
85 + Principal:
86 + Service:
87 + - "ec2.amazonaws.com"
88 + - "codedeploy.amazonaws.com"
89 + - "events.amazonaws.com"
90 + Action:
91 + - "sts:AssumeRole"
92 + Policies:
93 + -
94 + PolicyName: "allow-webapp-deployment-bucket-bucket"
95 + PolicyDocument:
96 + Version: "2012-10-17"
97 + Statement:
98 + -
99 + Effect: "Allow"
100 + Action: "s3:getObject"
101 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
102 + -
103 + Effect: Allow
104 + Action:
105 + - autoscaling:*
106 + - cloudwatch:*
107 + - logs:*
108 + - sns:*
109 + Resource: "*"
110 + WebappInstanceProfile:
111 + Type: "AWS::IAM::InstanceProfile"
112 + Properties:
113 + Roles:
114 + - Ref: WebappRole
115 + ALBSecurityGroup:
116 + Type: AWS::EC2::SecurityGroup
117 + Properties:
118 + GroupDescription: allow access to ALB from internet
119 + VpcId:
120 + Ref: VPC
121 + SecurityGroupIngress:
122 + - IpProtocol: tcp
123 + FromPort: '80'
124 + ToPort: '80'
125 + CidrIp: 0.0.0.0/0
126 + WebappSecurityGroup:
127 + Type: AWS::EC2::SecurityGroup
128 + Properties:
129 + GroupDescription: allow access to Webapp from ALB
130 + VpcId:
131 + Ref: VPC
132 + SecurityGroupIngress:
133 + - IpProtocol: tcp
134 + FromPort: '3000'
135 + ToPort: '3000'
136 + SourceSecurityGroupId:
137 + Ref: ALBSecurityGroup
138 + - IpProtocol: tcp
139 + FromPort: '22'
140 + ToPort: '22'
141 + CidrIp: 0.0.0.0/0
142 + WebappLaunchConfig:
143 + Type: AWS::AutoScaling::LaunchConfiguration
144 + Properties:
145 + AssociatePublicIpAddress: true
146 + ImageId:
147 + Ref: AMIID
148 + InstanceType: t2.micro
149 + KeyName:
150 + Ref: KeyName
151 + SecurityGroups:
152 + - Ref: WebappSecurityGroup
153 + IamInstanceProfile:
154 + Ref: WebappInstanceProfile
155 + UserData:
156 + Fn::Base64:
157 + !Sub |
158 + #! /bin/bash -xe
159 + # update yum just in case
160 + yum update -y
161 + # install codedeploy agent
162 + yum install -y ruby
163 + yum install -y wget
164 + cd /home/ec2-user
165 + # you have to notice region in url
166 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
167 + chmod +x ./install
168 + ./install auto
169 + # install cloudwatch logs agent
170 + sudo yum install -y awslogs
171 + # set config file sending log to right region
172 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
173 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
174 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
175 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
176 + # start cloudwatch agent
177 + sudo systemctl start awslogsd
178 + # get node into yum
179 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
180 + # install node and npm in one line
181 + yum install -y nodejs
182 + # install pm2 to restart node app
183 + npm i -g pm2@2.4.3
184 + AutoScalingGroup:
185 + Type: AWS::AutoScaling::AutoScalingGroup
186 + Properties:
187 + HealthCheckType: ELB
188 + HealthCheckGracePeriod: 300
189 + MinSize:
190 + Ref: MinSize
191 + MaxSize:
192 + Ref: MaxSize
193 + LaunchConfigurationName:
194 + Ref: WebappLaunchConfig
195 + VPCZoneIdentifier:
196 + Ref: WebappSubnets
197 + TargetGroupARNs:
198 + - Ref: ALBTargetGroup
199 + Tags:
200 + - Key: Name
201 + Value: webapp-example
202 + PropagateAtLaunch: true
203 + ALBListener:
204 + Type: AWS::ElasticLoadBalancingV2::Listener
205 + Properties:
206 + DefaultActions:
207 + -
208 + Type: forward
209 + TargetGroupArn:
210 + Ref: ALBTargetGroup
211 + LoadBalancerArn:
212 + Ref: LoadBalancer
213 + Port: 80
214 + Protocol: HTTP
215 + LoadBalancer:
216 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
217 + Properties:
218 + Name: testLoadbalancer
219 + Scheme: internet-facing
220 + Subnets:
221 + Ref: ALBSubnets
222 + SecurityGroups:
223 + - Ref: ALBSecurityGroup
224 + Tags:
225 + - Key: Name
226 + Value:
227 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
228 + ALBTargetGroup:
229 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
230 + Properties:
231 + TargetGroupAttributes:
232 + - Key: deregistration_delay.timeout_seconds
233 + Value: 30
234 + HealthCheckIntervalSeconds: 30
235 + UnhealthyThresholdCount: 2
236 + HealthyThresholdCount: 2
237 + HealthCheckPath: /
238 + Port: 3000
239 + Protocol: HTTP
240 + VpcId:
241 + Ref: VPC
242 + WebappApplication:
243 + Type: "AWS::CodeDeploy::Application"
244 + Properties:
245 + ApplicationName: testApp
246 + WebappDeploymentGroup:
247 + Type: "AWS::CodeDeploy::DeploymentGroup"
248 + Properties:
249 + DeploymentGroupName: test-group
250 + ApplicationName: !Ref WebappApplication
251 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
252 + DeploymentConfigName: CodeDeployDefault.OneAtATime
253 + DeploymentStyle:
254 + DeploymentType: IN_PLACE
255 + DeploymentOption: WITH_TRAFFIC_CONTROL
256 + LoadBalancerInfo:
257 + TargetGroupInfoList:
258 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
259 + AutoScalingGroups:
260 + - Ref: AutoScalingGroup
261 + WebappDeploymentBucket:
262 + Type: "AWS::S3::Bucket"
263 + Properties:
264 + BucketName: 'testtest11324'
265 +Outputs:
266 + WebappUrl:
267 + Description: Webapp URL
268 + Value: !GetAtt LoadBalancer.DNSName
269 + DeploymentGroup:
270 + Description: Webapp Deployment Group
271 + Value: !Ref WebappDeploymentGroup
272 + DeploymentBucket:
273 + Description: Deployment bucket
274 + Value: !Ref WebappDeploymentBucket
275 + ApplicationName:
276 + Description: CodeDeploy Application name
277 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +general]
2 +datetime_format = %Y-%m-%d %H:%M:%S
3 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
4 +log_stream_name = {instance_id}-codedeploy-agent-log
5 +log_group_name = codedeploy-agent-log
6 +
7 +[codedeploy-agent-logs]
8 +datetime_format = %Y-%m-%d %H:%M:%S
9 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
10 +log_stream_name = {instance_id}-codedeploy-agent-log
11 +log_group_name = codedeploy-agent-log
12 +
13 +[codedeploy-updater-logs]
14 +file = /tmp/codedeploy-agent.update.log
15 +log_stream_name = {instance_id}-codedeploy-updater-log
16 +log_group_name = codedeploy-updater-log
17 +
18 +[codedeploy-deployment-logs]
19 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
20 +log_stream_name = {instance_id}-codedeploy-deployments-log
21 +log_group_name = codedeploy-deployments-log
...\ No newline at end of file ...\ No newline at end of file
1 +[general]
2 +datetime_format = %Y-%m-%d %H:%M:%S
3 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
4 +log_stream_name = {instance_id}-codedeploy-agent-log
5 +log_group_name = codedeploy-agent-log
6 +
7 +[codedeploy-agent-logs]
8 +datetime_format = %Y-%m-%d %H:%M:%S
9 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
10 +log_stream_name = {instance_id}-codedeploy-agent-log
11 +log_group_name = codedeploy-agent-log
12 +
13 +[codedeploy-updater-logs]
14 +file = /tmp/codedeploy-agent.update.log
15 +log_stream_name = {instance_id}-codedeploy-updater-log
16 +log_group_name = codedeploy-updater-log
17 +
18 +[codedeploy-deployment-logs]
19 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
20 +log_stream_name = {instance_id}-codedeploy-deployments-log
21 +log_group_name = codedeploy-deployments-log
...\ No newline at end of file ...\ No newline at end of file
1 +#!/bin/bash
2 +
3 +# update yum just in case
4 +yum update -y
5 +# get node into yum
6 +curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
7 +# install node and npm in one line
8 +yum install -y nodejs
9 +# install pm2 to restart node app
10 +npm i -g pm2@2.4.3
...\ No newline at end of file ...\ No newline at end of file
1 +#!/bin/bash
2 +# update yum just in case
3 +yum update -y
4 +# get node into yum
5 +curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
6 +# install node and npm in one line
7 +yum install -y nodejs
8 +install pm2 to restart node app
9 +npm i -g pm2@2.4.3
...\ No newline at end of file ...\ No newline at end of file
1 +#!/bin/bash
2 +# update yum just in case
3 +yum update -y
4 +# get node into yum
5 +curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
6 +# install node and npm in one line
7 +yum install -y nodejs
8 +install pm2 to restart node app
9 +npm i -g pm2@2.4.3
10 +cd /home/ec2-user
11 +touch ddd.txt
...\ No newline at end of file ...\ No newline at end of file
1 +#!/bin/bash
2 +# update yum just in case
3 +yum update -y
4 +# get node into yum
5 +curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
6 +# install node and npm in one line
7 +yum install -y nodejs
8 +install pm2 to restart node app
9 +npm i -g pm2@2.4.3
...\ No newline at end of file ...\ No newline at end of file
1 +# IaC를 이용한 인프라 구성 / 자동 배포 / 배포 로그 수집
2 +## CloudFormation 인프라 구성 / CodeDeploy 자동 배포 / CloudWatch 로그 수집
3 +![cloudformaion.png](./img/cloudformation.png)
4 +## 전제사항
5 +* Nodejs 프로젝트 존재
6 + * 꼭 Nodejs일 필요는 없으나 Java Spring이나 Django로 바뀌게 될 경우 초기 설정이나 쉘 스크립트 수정이 필요
7 +* CloudFormation을 사용할 수 있는 IAM 계정 존재
8 +* CodeDeploy, CloudWatch Agent 설치된 AMI
9 + * AMI 없이 UserData로 설치 가능
10 +* 빌드 파일을 실행하기 위한 요소(Node or Java)가 설치된 AMI 존재
11 + * AMI 없이 UserData로 설치 가능
12 +* 프로젝트에 CodeDeploy 스펙을 정의한 appspec.yml 파일 존재
13 +
14 +## 자동 배포 진행 과정
15 +
16 +1. CloudFormation으로 LoadBalancer, Autoscaling Group, CodeDeploy 등 인프라 구성
17 +2. 배포하고자 하는 프로젝트 빌드 파일을 S3로 전송
18 +3. CodeDeploy를 사용하여 빌드된 프로젝트 파일 배포
19 +
20 +# CloudFormation 인프라 구성
21 +
22 +## json 또는 yaml 형식으로 인프라 정의
23 +* ### Parameters
24 + * Parameters의 경우 프로젝트마다 다른 설정값이 필요하거나 입력이 필요한 변수에 대한 정의
25 + * 예를 들면 subnetId, keyName, autoscaingMaxSize/Minsize 같은 경우에는 사용자마다 다른 ID나 설정값이 필요
26 + * 각각 자신의 설정에 맞게 변경
27 +```yaml
28 +Parameters:
29 + KeyName:
30 + Type: String
31 + Default: dd
32 + WebappSubnets:
33 + Type: CommaDelimitedList
34 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
35 + ALBSubnets:
36 + Type: CommaDelimitedList
37 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
38 + MinSize:
39 + Type: Number
40 + Default: 2
41 + MaxSize:
42 + Type: Number
43 + Default: 3
44 + VPC:
45 + Type: String
46 + Default: vpc-aab1aac2
47 + AMIID:
48 + Type: String
49 + Default: ami-08ab3f7e72215fe91
50 + NamePrefix:
51 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
52 + Default: bluegreen
53 + Description: Prefix for resource tags made by this template (2-15 chars).
54 + MaxLength: 15
55 + MinLength: 2
56 + Type: String
57 +```
58 +* ### Resource
59 + * Resouces에서는 인프라에 대한 세부사항 모두 정의
60 + * VPC부터 시작해서 모든 인프라 세부 요소에 대해서 정의를 할 수 있고 기존에 있는 리소스를 가져와서 사용할 수도 있다.
61 +* Role 설정
62 + * codedeploy가 loadbalancer와 autoscaling을 이용할 수 있도록 하는 설정
63 + * Instance가 cloudwatch와 codedeploy를 이용하고 s3로부터 코드를 가져올 수 있도록 하는 설정
64 +```yaml
65 +Resources:
66 + CodeDeployRole:
67 + Type: "AWS::IAM::Role"
68 + Properties:
69 + AssumeRolePolicyDocument:
70 + Version: "2012-10-17"
71 + Statement:
72 + -
73 + Effect: "Allow"
74 + Principal:
75 + Service:
76 + - "codedeploy.amazonaws.com"
77 + Action:
78 + - "sts:AssumeRole"
79 + Policies:
80 + -
81 + PolicyName: allow-autoscaling
82 + PolicyDocument:
83 + Version: "2012-10-17"
84 + Statement:
85 + -
86 + Effect: Allow
87 + Action:
88 + - ec2:*
89 + - autoscaling:*
90 + Resource: "*"
91 + -
92 + PolicyName: allow-loadbalance
93 + PolicyDocument:
94 + Version: "2012-10-17"
95 + Statement:
96 + -
97 + Effect: Allow
98 + Action:
99 + - ec2:*
100 + - autoscaling:*
101 + Resource: "*"
102 + -
103 + Effect: Allow
104 + Action:
105 + - iam:CreateServiceLinkedRole
106 + Resource: "*"
107 + -
108 + Effect: Allow
109 + Action:
110 + - elasticloadbalancing:*
111 + Resource: "*"
112 + WebappRole:
113 + Type: "AWS::IAM::Role"
114 + Properties:
115 + AssumeRolePolicyDocument:
116 + Version: "2012-10-17"
117 + Statement:
118 + -
119 + Effect: "Allow"
120 + Principal:
121 + Service:
122 + - "ec2.amazonaws.com"
123 + - "codedeploy.amazonaws.com"
124 + - "events.amazonaws.com"
125 + Action:
126 + - "sts:AssumeRole"
127 + Policies:
128 + -
129 + PolicyName: "allow-webapp-deployment-bucket-bucket"
130 + PolicyDocument:
131 + Version: "2012-10-17"
132 + Statement:
133 + -
134 + Effect: "Allow"
135 + Action: "s3:getObject"
136 + Resource: !Sub arn:aws:s3:::${WebappDeploymentBucket}/*
137 + -
138 + Effect: Allow
139 + Action:
140 + - autoscaling:*
141 + - cloudwatch:*
142 + - logs:*
143 + - sns:*
144 + Resource: "*"
145 +```
146 +* 실제 인프라 구성에 대한 정의
147 + * security Group
148 + * autoscaling group
149 + * loadbalancer 등등
150 +```yaml
151 + WebappInstanceProfile:
152 + Type: "AWS::IAM::InstanceProfile"
153 + Properties:
154 + Roles:
155 + - Ref: WebappRole
156 + ALBSecurityGroup:
157 + Type: AWS::EC2::SecurityGroup
158 + Properties:
159 + GroupDescription: allow access to ALB from internet
160 + VpcId:
161 + Ref: VPC
162 + SecurityGroupIngress:
163 + - IpProtocol: tcp
164 + FromPort: '80'
165 + ToPort: '80'
166 + CidrIp: 0.0.0.0/0
167 + WebappSecurityGroup:
168 + Type: AWS::EC2::SecurityGroup
169 + Properties:
170 + GroupDescription: allow access to Webapp from ALB
171 + VpcId:
172 + Ref: VPC
173 + SecurityGroupIngress:
174 + - IpProtocol: tcp
175 + FromPort: '3000'
176 + ToPort: '3000'
177 + SourceSecurityGroupId:
178 + Ref: ALBSecurityGroup
179 + - IpProtocol: tcp
180 + FromPort: '22'
181 + ToPort: '22'
182 + CidrIp: 0.0.0.0/0
183 + WebappLaunchConfig:
184 + Type: AWS::AutoScaling::LaunchConfiguration
185 + Properties:
186 + AssociatePublicIpAddress: true
187 + ImageId:
188 + Ref: AMIID
189 + InstanceType: t2.micro
190 + KeyName:
191 + Ref: KeyName
192 + SecurityGroups:
193 + - Ref: WebappSecurityGroup
194 + IamInstanceProfile:
195 + Ref: WebappInstanceProfile
196 + UserData:
197 + Fn::Base64:
198 + !Sub |
199 + #! /bin/bash -xe
200 + # update yum just in case
201 + yum update -y
202 + # install codedeploy agent
203 + yum install -y ruby
204 + yum install -y wget
205 + cd /home/ec2-user
206 + # you have to notice region in url
207 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
208 + chmod +x ./install
209 + ./install auto
210 + # install cloudwatch logs agent
211 + sudo yum install -y awslogs
212 + # set config file sending log to right region
213 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
214 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
215 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
216 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
217 + # start cloudwatch agent
218 + sudo systemctl start awslogsd
219 + # get node into yum
220 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
221 + # install node and npm in one line
222 + yum install -y nodejs
223 + # install pm2 to restart node app
224 + npm i -g pm2@2.4.3
225 + AutoScalingGroup:
226 + Type: AWS::AutoScaling::AutoScalingGroup
227 + Properties:
228 + HealthCheckType: ELB
229 + HealthCheckGracePeriod: 300
230 + MinSize:
231 + Ref: MinSize
232 + MaxSize:
233 + Ref: MaxSize
234 + LaunchConfigurationName:
235 + Ref: WebappLaunchConfig
236 + VPCZoneIdentifier:
237 + Ref: WebappSubnets
238 + TargetGroupARNs:
239 + - Ref: ALBTargetGroup
240 + Tags:
241 + - Key: Name
242 + Value: webapp-example
243 + PropagateAtLaunch: true
244 + ALBListener:
245 + Type: AWS::ElasticLoadBalancingV2::Listener
246 + Properties:
247 + DefaultActions:
248 + -
249 + Type: forward
250 + TargetGroupArn:
251 + Ref: ALBTargetGroup
252 + LoadBalancerArn:
253 + Ref: LoadBalancer
254 + Port: 80
255 + Protocol: HTTP
256 + LoadBalancer:
257 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
258 + Properties:
259 + Name: testLoadbalancer
260 + Scheme: internet-facing
261 + Subnets:
262 + Ref: ALBSubnets
263 + SecurityGroups:
264 + - Ref: ALBSecurityGroup
265 + Tags:
266 + - Key: Name
267 + Value:
268 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
269 + ALBTargetGroup:
270 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
271 + Properties:
272 + TargetGroupAttributes:
273 + - Key: deregistration_delay.timeout_seconds
274 + Value: 30
275 + HealthCheckIntervalSeconds: 30
276 + UnhealthyThresholdCount: 2
277 + HealthyThresholdCount: 2
278 + HealthCheckPath: /
279 + Port: 3000
280 + Protocol: HTTP
281 + VpcId:
282 + Ref: VPC
283 +```
284 +* codedeploy 설정
285 + * codedeploy application을 설정
286 + * codedeploy group을 이용하여 세부 배포 설정
287 +```yaml
288 + WebappApplication:
289 + Type: "AWS::CodeDeploy::Application"
290 + Properties:
291 + ApplicationName: testApp
292 + WebappDeploymentGroup:
293 + Type: "AWS::CodeDeploy::DeploymentGroup"
294 + Properties:
295 + DeploymentGroupName: test-group
296 + ApplicationName: !Ref WebappApplication
297 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
298 + DeploymentConfigName: CodeDeployDefault.OneAtATime
299 + DeploymentStyle:
300 + DeploymentType: IN_PLACE
301 + DeploymentOption: WITH_TRAFFIC_CONTROL
302 + LoadBalancerInfo:
303 + TargetGroupInfoList:
304 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
305 + AutoScalingGroups:
306 + - Ref: AutoScalingGroup
307 + WebappDeploymentBucket:
308 + Type: "AWS::S3::Bucket"
309 + Properties:
310 + BucketName: 'testtest11324'
311 +```
312 +* ### output
313 + * loadbalancer dns와 같이 인프라 생성이후에 정의되는 변수들을 출력하여 굳이 콘솔에서 로드밸런서 주소를 확인하지 않아도 된다
314 +```yaml
315 +Outputs:
316 + WebappUrl:
317 + Description: Webapp URL
318 + Value: !GetAtt LoadBalancer.DNSName
319 + DeploymentGroup:
320 + Description: Webapp Deployment Group
321 + Value: !Ref WebappDeploymentGroup
322 + DeploymentBucket:
323 + Description: Deployment bucket
324 + Value: !Ref WebappDeploymentBucket
325 + ApplicationName:
326 + Description: CodeDeploy Application name
327 + Value: !Ref WebappApplication
328 +```
329 +* ### Cloudformation 스택 생성
330 +```
331 +$ aws cloudformation create-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
332 +```
333 +* ### Cloudformation 스택 업데이트
334 + * 변경하고 싶은 인프라가 있을 경우 콘솔에서 수정하는 것이 아니라 코드에서 수정해야 한다.
335 + * 콘솔에서 임의로 수정할 시 다시 스택을 생성하거나 삭제할 때 오류 발생
336 +```
337 +$ aws cloudformation update-stack --stack-name test-template-1 --template-body file:///Users/huhjin-ho/Desktop/IaC/cloudformation/codedeploy/code_deploy.yaml --capabilities CAPABILITY_IAM
338 +```
339 +* ### Cloudformation 스택 삭제
340 +```
341 +$ aws cloudformation delete-stack --stack-name test-template-1
342 +```
343 +
344 +# 빌드 파일 S3 전송
345 +```
346 +aws deploy push --application-name testApp --s3-location s3://testtest11324/test-4.zip --source webapp
347 +```
348 +
349 +# 빌드된 파일 배포
350 +
351 +## 배포 방식 종류
352 +* ### In Place 방식
353 + * 기존에 존재하는 인스턴스에 배포하는 방식
354 +* ### Blue / Green 방식
355 + * 기존에 존재하는 인스턴스는 그대로 두고 새로운 autoscaling group에 배포 후 정상 배포시 교체하는 방식
356 +
357 +## LoadBalancer로 트래픽 분배
358 +* 배포하는 동안 오류가 발생할 수 있으므로 Loadbalancer를 이용하여 배포 도중에 트래픽 자동 관리
359 +
360 +## appspec.yml 설정
361 +```
362 +version: 0.0
363 +os: linux
364 +files:
365 + - source: src
366 + destination: /opt/webapp
367 + - source: node_modules
368 + destination: /opt/webapp/node_modules
369 +hooks:
370 + ApplicationStop:
371 + - location: deployment_scripts/stop.sh
372 + timeout: 180
373 + AfterInstall:
374 + - location: deployment_scripts/deploy.sh
375 + timeout: 180
376 + ApplicationStart:
377 + - location: deployment_scripts/start.sh
378 + timeout: 180
379 +
380 +```
381 +* ### start.sh
382 + * 빌드된 프로젝트를 실행하는 스크립트로 현재는 Node를 기준으로 작성되어 있음
383 + * 각각 자신의 빌드된 프로젝트를 실행하는 코드로 바꿔주면 똑같이 적용 가능
384 +```
385 +#!/usr/bin/env bash
386 +
387 +sudo pm2 stop node-app
388 +# actually start the server
389 +sudo pm2 start /opt/webapp/index.js -i 0 --name "node-app"
390 +```
391 +* ### stop.sh
392 + * 빌드된 프로젝트를 중지하는 스크립트로 현재는 Node를 기준으로 작성되어 있음
393 + * 각각 자신의 빌드된 프로젝트를 중지하는 코드로 바꿔주면 똑같이 적용 가능
394 +```
395 +#!/usr/bin/env bash
396 +
397 +sudo pm2 stop node-app
398 +sleep 10
399 +```
400 +
401 +## 명령어
402 +```
403 +aws deploy create-deployment --application-name testApp --s3-location bucket="testtest11324",key="test-4.zip",bundleType=zip --deployment-group-name test-group
404 +```
405 +
406 +# 배포 관련 로그 확인
407 +
408 +## UserData
409 +* UserData 설정
410 + * Autoscaling Instance 생성시 자동 실행되는 스크립트
411 + * 현재 CloudFormation 정의 파일에 사용됨 - code_deploy.yaml
412 + * cloudwatch를 실행하는 코드 아래로는 Node 기준으로 작성되어 있음
413 + * Node 관련 코드 아래로는 자신의 프로젝트 실행을 위한 Dependcies 설치 코드로 바꿔주면 똑같이 적용 가능
414 + * 예를 들어 빌드 파일이 jar 형식인 경우에는 맞는 버젼의 java를 설치
415 +* AMI
416 + * userdata를 사용하지 않고 스크립트 내용을 직접 인스턴스의 실행하여 AMI로 빌드하여 사용 가능
417 + * 위와 같은 경우에는 대신 autoscaling에 사용되는 AMI ID를 자신이 만든 AMI를 사용해야 함
418 +* 스크립트 내용
419 + * codedeploy, cloudwathch logs agent 설치(필수)
420 + * cloudwatch 설정 파일 생성(필수)
421 + * dependcies 설치(상황에 따른 설치 필요)
422 + * pm2 설치(노드 시작/중단 사용하기 위함)(상황에 따른 설치 필요)
423 +```yaml
424 +UserData:
425 + Fn::Base64:
426 + !Sub |
427 + #! /bin/bash -xe
428 + # update yum just in case
429 + yum update -y
430 + # install codedeploy agent
431 + yum install -y ruby
432 + yum install -y wget
433 + cd /home/ec2-user
434 + # you have to notice region in url
435 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
436 + chmod +x ./install
437 + ./install auto
438 + # install cloudwatch logs agent
439 + sudo yum install -y awslogs
440 + # set config file sending log to right region
441 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
442 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
443 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
444 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
445 + # start cloudwatch agent
446 + sudo systemctl start awslogsd
447 + ################### Node Dependcies ###############################
448 + curl --silent --location https://rpm.nodesource.com/setup_6.x | bash -
449 + # install node and npm in one line
450 + yum install -y nodejs
451 + # install pm2 to restart node app
452 + npm i -g pm2@2.4.3
453 + ###################################################################
454 +```
455 +## CloudWatch 로그 설정
456 + * cloudwatch에 로그를 남기기 위한 설정 파일들
457 + * awscli.conf, awslogs.conf 두 개로 구성
458 + * awscli.conf
459 + * region이나 plugin 정의
460 + * awslogs.conf
461 + * 로그로 남기고 싶은 파일에 대한 정의
462 + * application 로그도 가능
463 +```
464 +#/etc/awslogs/awscli.conf
465 +
466 +[plugins]
467 +cwlogs = cwlogs ## plugin 지정
468 +[default]
469 +region = ap-northeast-2 ## cloudwatch region 지정
470 +```
471 +
472 +```
473 +#/etc/awslogs/awslogs.conf
474 +
475 +[general] ## general 없을 시 오류 발생
476 +datetime_format = %Y-%m-%d %H:%M:%S
477 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
478 +log_stream_name = {instance_id}-codedeploy-agent-log
479 +log_group_name = codedeploy-agent-log
480 +
481 +[codedeploy-agent-logs]
482 +datetime_format = %Y-%m-%d %H:%M:%S
483 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
484 +log_stream_name = {instance_id}-codedeploy-agent-log
485 +log_group_name = codedeploy-agent-log
486 +
487 +[codedeploy-updater-logs]
488 +file = /tmp/codedeploy-agent.update.log
489 +log_stream_name = {instance_id}-codedeploy-updater-log
490 +log_group_name = codedeploy-updater-log
491 +
492 +[codedeploy-deployment-logs]
493 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
494 +log_stream_name = {instance_id}-codedeploy-deployments-log
495 +log_group_name = codedeploy-deployments-log
496 +```
497 +
498 +* ### CloudWatch가 제대로 작동 안할 시 확인을 위한 로그 위치
499 +```
500 +/var/log/awslogs.log
501 +```
1 +[plugins]
2 +cwlogs = cwlogs
3 +[default]
4 +region = ap-northeast-2
...\ No newline at end of file ...\ No newline at end of file
1 +Parameters:
2 + BranchName:
3 + Description: GitHub branch name
4 + Type: String
5 + Default: 'master'
6 + RepositoryName:
7 + Description: GitHub repository name
8 + Type: String
9 + # Default: '깃허브 repo name'
10 + GitHubOwner:
11 + Type: String
12 + # Default: '깃허브 ID'
13 + GitHubOAuthToken:
14 + Type: String
15 + # Default: '깃허브 OAuth Token'
16 + NoEcho: true
17 + GitHubSecret:
18 + Type: String
19 + # Default: '깃허브 비밀번호'
20 + NoEcho: true
21 + KeyName:
22 + Type: String
23 + Default: iot
24 + VPC:
25 + Type: String
26 + Default: vpc-aab1aac2
27 + WebappSubnets:
28 + Type: CommaDelimitedList
29 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
30 + ALBSubnets:
31 + Type: CommaDelimitedList
32 + Default: subnet-c44697bf, subnet-e8756180, subnet-e87f07a4
33 + AMIID:
34 + Type: String
35 + Default: ami-08ab3f7e72215fe91
36 + MinSize:
37 + Type: Number
38 + Default: 2
39 + MaxSize:
40 + Type: Number
41 + Default: 3
42 + NamePrefix:
43 + AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
44 + Default: bluegreen
45 + Description: Prefix for resource tags made by this template (2-15 chars).
46 + MaxLength: 15
47 + MinLength: 2
48 + Type: String
49 + CommitId:
50 + Type: String
51 + Default: 'ddd'
52 + Repository:
53 + Type: String
54 + Default: 'ddd'
55 + HashKeyElementName:
56 + Description: HashType PrimaryKey Name
57 + Default: test
58 + Type: String
59 + AllowedPattern: '[a-zA-Z0-9]*'
60 + MinLength: 1
61 + MaxLength: 2048
62 + ConstraintDescription: must contain only alphanumberic characters
63 + HashKeyElementType:
64 + Description: HashType PrimaryKey Type
65 + Type: String
66 + Default: S
67 + AllowedPattern: '[S|N]'
68 + MinLength: 1
69 + MaxLength: 1
70 + ConstraintDescription: must be either S or N
71 + ReadCapacityUnits:
72 + Description: Provisioned read throughput
73 + Type: Number
74 + Default: 5
75 + MinValue: 5
76 + MaxValue: 10000
77 + ConstraintDescription: must be between 5 and 10000
78 + WriteCapacityUnits:
79 + Description: Provisioned write throughput
80 + Type: Number
81 + Default: 10
82 + MinValue: 5
83 + MaxValue: 10000
84 + ConstraintDescription: must be between 5 and 10000
85 +Resources:
86 + CodeDeployRole:
87 + Type: "AWS::IAM::Role"
88 + Properties:
89 + AssumeRolePolicyDocument:
90 + Version: "2012-10-17"
91 + Statement:
92 + -
93 + Effect: "Allow"
94 + Principal:
95 + Service:
96 + - "codedeploy.amazonaws.com"
97 + Action:
98 + - "sts:AssumeRole"
99 + Policies:
100 + -
101 + PolicyName: allow-autoscaling
102 + PolicyDocument:
103 + Version: "2012-10-17"
104 + Statement:
105 + -
106 + Effect: Allow
107 + Action:
108 + - ec2:*
109 + - autoscaling:*
110 + Resource: "*"
111 + -
112 + PolicyName: allow-loadbalance
113 + PolicyDocument:
114 + Version: "2012-10-17"
115 + Statement:
116 + -
117 + Effect: Allow
118 + Action:
119 + - ec2:*
120 + - autoscaling:*
121 + Resource: "*"
122 + -
123 + Effect: Allow
124 + Action:
125 + - iam:CreateServiceLinkedRole
126 + Resource: "*"
127 + -
128 + Effect: Allow
129 + Action:
130 + - elasticloadbalancing:*
131 + Resource: "*"
132 + WebappRole:
133 + Type: "AWS::IAM::Role"
134 + Properties:
135 + AssumeRolePolicyDocument:
136 + Version: "2012-10-17"
137 + Statement:
138 + -
139 + Effect: "Allow"
140 + Principal:
141 + Service:
142 + - "ec2.amazonaws.com"
143 + - "codedeploy.amazonaws.com"
144 + - "events.amazonaws.com"
145 + - "dynamodb.amazonaws.com"
146 + Action:
147 + - "sts:AssumeRole"
148 + Policies:
149 + -
150 + PolicyName: "allow-webapp-deployment-bucket-bucket"
151 + PolicyDocument:
152 + Version: "2012-10-17"
153 + Statement:
154 + -
155 + Effect: "Allow"
156 + Action: "s3:getObject"
157 + Resource: !Sub arn:aws:s3:::${CodePipelineArtifactStoreBucket}/*
158 + -
159 + Effect: Allow
160 + Action:
161 + - autoscaling:*
162 + - cloudwatch:*
163 + - logs:*
164 + - sns:*
165 + - dynamodb:*
166 + Resource: "*"
167 + WebappInstanceProfile:
168 + Type: "AWS::IAM::InstanceProfile"
169 + Properties:
170 + Roles:
171 + - Ref: WebappRole
172 + ALBSecurityGroup:
173 + Type: AWS::EC2::SecurityGroup
174 + Properties:
175 + GroupDescription: allow access to ALB from internet
176 + VpcId:
177 + Ref: VPC
178 + SecurityGroupIngress:
179 + - IpProtocol: tcp
180 + FromPort: '80'
181 + ToPort: '80'
182 + CidrIp: 0.0.0.0/0
183 + WebappSecurityGroup:
184 + Type: AWS::EC2::SecurityGroup
185 + Properties:
186 + GroupDescription: allow access to Webapp from ALB
187 + VpcId:
188 + Ref: VPC
189 + SecurityGroupIngress:
190 + - IpProtocol: tcp
191 + FromPort: '3000'
192 + ToPort: '3000'
193 + SourceSecurityGroupId:
194 + Ref: ALBSecurityGroup
195 + - IpProtocol: tcp
196 + FromPort: '22'
197 + ToPort: '22'
198 + CidrIp: 0.0.0.0/0
199 + WebappLaunchConfig:
200 + Type: AWS::AutoScaling::LaunchConfiguration
201 + Properties:
202 + AssociatePublicIpAddress: true
203 + ImageId:
204 + Ref: AMIID
205 + InstanceType: t2.micro
206 + KeyName:
207 + Ref: KeyName
208 + SecurityGroups:
209 + - Ref: WebappSecurityGroup
210 + IamInstanceProfile:
211 + Ref: WebappInstanceProfile
212 + UserData:
213 + Fn::Base64:
214 + !Sub |
215 + #! /bin/bash -xe
216 + # update yum just in case
217 + yum update -y
218 + # install codedeploy agent
219 + yum install -y ruby
220 + yum install -y wget
221 + cd /home/ec2-user
222 + # you have to notice region in url
223 + curl -O https://aws-codedeploy-ap-northeast-2.s3.amazonaws.com/latest/install
224 + chmod +x ./install
225 + ./install auto
226 + # install cloudwatch logs agent
227 + sudo yum install -y awslogs
228 + # set config file sending log to right region
229 + echo -e "[general]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-agent-logs]\ndatetime_format = %Y-%m-%d %H:%M:%S\nfile = /var/log/aws/codedeploy-agent/codedeploy-agent.log\nlog_stream_name = {instance_id}-codedeploy-agent-log\nlog_group_name = codedeploy-agent-log\n\n[codedeploy-updater-logs]\nfile = /tmp/codedeploy-agent.update.log\nlog_stream_name = {instance_id}-codedeploy-updater-log\nlog_group_name = codedeploy-updater-log\n\n[codedeploy-deployment-logs]\nfile = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log\nlog_stream_name = {instance_id}-codedeploy-deployments-log\nlog_group_name = codedeploy-deployments-log" > codedeploy_logs.conf
230 + echo -e "[plugins]\ncwlogs = cwlogs\n[default]\nregion = ap-northeast-2" > codedeploy_cli.conf
231 + sudo cp ./codedeploy_logs.conf /etc/awslogs/awslogs.conf
232 + sudo cp ./codedeploy_cli.conf /etc/awslogs/awscli.conf
233 + # start cloudwatch agent
234 + sudo systemctl start awslogsd
235 + # get node into yum
236 + curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
237 + # install node and npm in one line
238 + yum install -y nodejs
239 + # install pm2 to restart node app
240 + npm i -g pm2@2.4.3
241 + AutoScalingGroup:
242 + Type: AWS::AutoScaling::AutoScalingGroup
243 + Properties:
244 + HealthCheckType: ELB
245 + HealthCheckGracePeriod: 300
246 + MinSize:
247 + Ref: MinSize
248 + MaxSize:
249 + Ref: MaxSize
250 + LaunchConfigurationName:
251 + Ref: WebappLaunchConfig
252 + VPCZoneIdentifier:
253 + Ref: WebappSubnets
254 + TargetGroupARNs:
255 + - Ref: ALBTargetGroup
256 + Tags:
257 + - Key: Name
258 + Value: webapp-example
259 + PropagateAtLaunch: true
260 + ALBListener:
261 + Type: AWS::ElasticLoadBalancingV2::Listener
262 + Properties:
263 + DefaultActions:
264 + -
265 + Type: forward
266 + TargetGroupArn:
267 + Ref: ALBTargetGroup
268 + LoadBalancerArn:
269 + Ref: LoadBalancer
270 + Port: 80
271 + Protocol: HTTP
272 + LoadBalancer:
273 + Type: AWS::ElasticLoadBalancingV2::LoadBalancer
274 + Properties:
275 + Name: testLoadbalancer
276 + Scheme: internet-facing
277 + Subnets:
278 + Ref: ALBSubnets
279 + SecurityGroups:
280 + - Ref: ALBSecurityGroup
281 + Tags:
282 + - Key: Name
283 + Value:
284 + !Join ["", [ Ref: NamePrefix, "-elb"] ]
285 + ALBTargetGroup:
286 + Type: AWS::ElasticLoadBalancingV2::TargetGroup
287 + Properties:
288 + TargetGroupAttributes:
289 + - Key: deregistration_delay.timeout_seconds
290 + Value: 30
291 + HealthCheckIntervalSeconds: 30
292 + UnhealthyThresholdCount: 2
293 + HealthyThresholdCount: 2
294 + HealthCheckPath: /
295 + Port: 3000
296 + Protocol: HTTP
297 + VpcId:
298 + Ref: VPC
299 + WebappApplication:
300 + Type: "AWS::CodeDeploy::Application"
301 + Properties:
302 + ApplicationName: testApp
303 + WebappDeploymentGroup:
304 + Type: "AWS::CodeDeploy::DeploymentGroup"
305 + Properties:
306 + DeploymentGroupName: test-group
307 + ApplicationName: !Ref WebappApplication
308 + ServiceRoleArn: !GetAtt CodeDeployRole.Arn
309 + DeploymentConfigName: CodeDeployDefault.OneAtATime
310 + DeploymentStyle:
311 + DeploymentType: IN_PLACE
312 + DeploymentOption: WITH_TRAFFIC_CONTROL
313 + LoadBalancerInfo:
314 + TargetGroupInfoList:
315 + - Name: !GetAtt ALBTargetGroup.TargetGroupName
316 + AutoScalingGroups:
317 + - Ref: AutoScalingGroup
318 + CodePipelineArtifactStoreBucket:
319 + Type: 'AWS::S3::Bucket'
320 + CodePipelineArtifactStoreBucketPolicy:
321 + Type: 'AWS::S3::BucketPolicy'
322 + Properties:
323 + Bucket: !Ref CodePipelineArtifactStoreBucket
324 + PolicyDocument:
325 + Version: 2012-10-17
326 + Statement:
327 + - Sid: DenyUnEncryptedObjectUploads
328 + Effect: Deny
329 + Principal: '*'
330 + Action: 's3:PutObject'
331 + Resource: !Join
332 + - ''
333 + - - !GetAtt
334 + - CodePipelineArtifactStoreBucket
335 + - Arn
336 + - /*
337 + Condition:
338 + StringNotEquals:
339 + 's3:x-amz-server-side-encryption': 'aws:kms'
340 + - Sid: DenyInsecureConnections
341 + Effect: Deny
342 + Principal: '*'
343 + Action: 's3:*'
344 + Resource: !Join
345 + - ''
346 + - - !GetAtt
347 + - CodePipelineArtifactStoreBucket
348 + - Arn
349 + - /*
350 + Condition:
351 + Bool:
352 + 'aws:SecureTransport': false
353 + AppPipelineWebhook:
354 + Type: 'AWS::CodePipeline::Webhook'
355 + Properties:
356 + Authentication: GITHUB_HMAC
357 + AuthenticationConfiguration:
358 + SecretToken: !Ref GitHubSecret
359 + Filters:
360 + - JsonPath: $.ref
361 + MatchEquals: 'refs/heads/{Branch}'
362 + TargetPipeline: !Ref AppPipeline
363 + TargetAction: SourceAction
364 + Name: AppPipelineWebhook
365 + TargetPipelineVersion: !GetAtt
366 + - AppPipeline
367 + - Version
368 + RegisterWithThirdParty: true
369 + AppPipeline:
370 + Type: 'AWS::CodePipeline::Pipeline'
371 + Properties:
372 + Name: github-events-pipeline
373 + RoleArn: !GetAtt
374 + - CodePipelineServiceRole
375 + - Arn
376 + Stages:
377 + - Name: Source
378 + Actions:
379 + - Name: SourceAction
380 + ActionTypeId:
381 + Category: Source
382 + Owner: ThirdParty
383 + Version: 1
384 + Provider: GitHub
385 + OutputArtifacts:
386 + - Name: SourceOutput
387 + Configuration:
388 + Owner: !Ref GitHubOwner
389 + Repo: !Ref RepositoryName
390 + Branch: !Ref BranchName
391 + OAuthToken: !Ref GitHubOAuthToken
392 + PollForSourceChanges: false
393 + RunOrder: 1
394 + - Name: Beta
395 + Actions:
396 + - Name: BetaAction
397 + InputArtifacts:
398 + - Name: SourceOutput
399 + ActionTypeId:
400 + Category: Deploy
401 + Owner: AWS
402 + Version: 1
403 + Provider: CodeDeploy
404 + Configuration:
405 + ApplicationName: !Ref WebappApplication
406 + DeploymentGroupName: !Ref WebappDeploymentGroup
407 + RunOrder: 1
408 + ArtifactStore:
409 + Type: S3
410 + Location: !Ref CodePipelineArtifactStoreBucket
411 + CodePipelineServiceRole:
412 + Type: 'AWS::IAM::Role'
413 + Properties:
414 + AssumeRolePolicyDocument:
415 + Version: 2012-10-17
416 + Statement:
417 + - Effect: Allow
418 + Principal:
419 + Service:
420 + - codepipeline.amazonaws.com
421 + Action: 'sts:AssumeRole'
422 + Path: /
423 + Policies:
424 + - PolicyName: AWS-CodePipeline-Service-3
425 + PolicyDocument:
426 + Version: 2012-10-17
427 + Statement:
428 + - Effect: Allow
429 + Action:
430 + - 'codecommit:CancelUploadArchive'
431 + - 'codecommit:GetBranch'
432 + - 'codecommit:GetCommit'
433 + - 'codecommit:GetUploadArchiveStatus'
434 + - 'codecommit:UploadArchive'
435 + Resource: '*'
436 + - Effect: Allow
437 + Action:
438 + - 'codedeploy:CreateDeployment'
439 + - 'codedeploy:GetApplicationRevision'
440 + - 'codedeploy:GetDeployment'
441 + - 'codedeploy:GetDeploymentConfig'
442 + - 'codedeploy:RegisterApplicationRevision'
443 + Resource: '*'
444 + - Effect: Allow
445 + Action:
446 + - 'codebuild:BatchGetBuilds'
447 + - 'codebuild:StartBuild'
448 + Resource: '*'
449 + - Effect: Allow
450 + Action:
451 + - 'devicefarm:ListProjects'
452 + - 'devicefarm:ListDevicePools'
453 + - 'devicefarm:GetRun'
454 + - 'devicefarm:GetUpload'
455 + - 'devicefarm:CreateUpload'
456 + - 'devicefarm:ScheduleRun'
457 + Resource: '*'
458 + - Effect: Allow
459 + Action:
460 + - 'lambda:InvokeFunction'
461 + - 'lambda:ListFunctions'
462 + Resource: '*'
463 + - Effect: Allow
464 + Action:
465 + - 'iam:PassRole'
466 + Resource: '*'
467 + - Effect: Allow
468 + Action:
469 + - 'elasticbeanstalk:*'
470 + - 'ec2:*'
471 + - 'elasticloadbalancing:*'
472 + - 'autoscaling:*'
473 + - 'cloudwatch:*'
474 + - 's3:*'
475 + - 'sns:*'
476 + - 'cloudformation:*'
477 + - 'rds:*'
478 + - 'sqs:*'
479 + - 'ecs:*'
480 + Resource: '*'
481 +
482 +Outputs:
483 + WebappUrl:
484 + Description: Webapp URL
485 + Value: !GetAtt LoadBalancer.DNSName
486 + DeploymentGroup:
487 + Description: Webapp Deployment Group
488 + Value: !Ref WebappDeploymentGroup
489 + DeploymentBucket:
490 + Description: Deployment bucket
491 + Value: !Ref CodePipelineArtifactStoreBucket
492 + ApplicationName:
493 + Description: CodeDeploy Application name
494 + Value: !Ref WebappApplication
...\ No newline at end of file ...\ No newline at end of file
1 +[general]
2 +datetime_format = %Y-%m-%d %H:%M:%S
3 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
4 +log_stream_name = {instance_id}-codedeploy-agent-log
5 +log_group_name = codedeploy-agent-log
6 +
7 +[codedeploy-agent-logs]
8 +datetime_format = %Y-%m-%d %H:%M:%S
9 +file = /var/log/aws/codedeploy-agent/codedeploy-agent.log
10 +log_stream_name = {instance_id}-codedeploy-agent-log
11 +log_group_name = codedeploy-agent-log
12 +
13 +[codedeploy-updater-logs]
14 +file = /tmp/codedeploy-agent.update.log
15 +log_stream_name = {instance_id}-codedeploy-updater-log
16 +log_group_name = codedeploy-updater-log
17 +
18 +[codedeploy-deployment-logs]
19 +file = /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
20 +log_stream_name = {instance_id}-codedeploy-deployments-log
21 +log_group_name = codedeploy-deployments-log
...\ No newline at end of file ...\ No newline at end of file
1 +[
2 + {
3 + "ParameterKey": "GitHubSecret",
4 + "ParameterValue": "dkfkq486!!"
5 + },
6 + {
7 + "ParameterKey": "GitHubOAuthToken",
8 + "ParameterValue": "aca8a09cb98c024bb8e08c70e7b5e5d6810a4a67"
9 + }
10 +]
...\ No newline at end of file ...\ No newline at end of file
webapp @ 32362320
1 +Subproject commit 3236232079d81087ee6779acf62cecbe216e76a9