-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfrastructure.yml
executable file
·814 lines (775 loc) · 26 KB
/
infrastructure.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
AWSTemplateFormatVersion: '2010-09-09'
Description: The template creates an ephemeral infrastructure, a default user and a temporary password.
It assumes you have a keypair, and an EFS file system.
Things that you can change in the template are written in comments.
Parameters:
EnvironmentName:
Description: An environment name that will be prefixed to resource names
Type: String
Default: Customer
ECRRepoParam:
Type: String
Description: Choose a name for the ECR repository. (must be lowercase)
Default: customer-repository
ClusterSize:
Description: How many ECS hosts do you want to initially deploy?
Type: Number
Default: 1
ClusterMaxSize:
Description: What is the maximum ASG scaling?
Type: Number
Default: 2
ECSAMI:
Description: ECS-Optimized AMI ID
Type: AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>
Default: /aws/service/ecs/optimized-ami/amazon-linux-2/recommended/image_id
Subnets:
Description: Choose which subnets the ECS autoscaling group will launch instances in
Type: List<AWS::EC2::Subnet::Id>
Default: <Enter a default subnet ID> #change the subnet id
EFSFileSystem:
Description: Enter your EFS filesystem id that will be attached to the task definition of the container
Type: String
VPCID:
Description: Enter the VPC ID that the security group of the ECS instance will reside in
Type: AWS::EC2::VPC::Id
TempPassword:
Description: The temporary password for the IAM user
Type: String
AMISize:
Description: The size of the EC2 instance that will be attached to the ECS cluster
Type: String
Default: t2.micro
EC2KeyPair:
Description: The keypair that will be attached to the instance upon creation
Type: AWS::EC2::KeyPair::KeyName
DesiredTasks:
Description: The desired tasks for the service. If this is the first time the template is being deployed, keep at 0 and change it manually.
Type: Number
Default: 0
IAMUserName:
Description: The name of the IAM user to create
Type: String
Resources:
ECRRepo:
Type: AWS::ECR::Repository
Properties:
EncryptionConfiguration:
EncryptionType: AES256
RepositoryName: !Ref ECRRepoParam
ECSCluster:
Type: AWS::ECS::Cluster
Properties:
ClusterName: !Ref EnvironmentName
ClusterSettings:
- Name: containerInsights
Value: enabled
ECSTaskDefinition:
Type: AWS::ECS::TaskDefinition
Properties:
ContainerDefinitions:
- Image: !GetAtt ECRRepo.RepositoryUri
Name: CustomerContainer
Memory: 512
MountPoints:
- SourceVolume: logs
ContainerPath: /logs
Volumes:
- Name: logs
EFSVolumeConfiguration:
FilesystemId: !Ref EFSFileSystem
RootDirectory: /
TransitEncryption: ENABLED
ECSRole:
Type: AWS::IAM::Role
Properties:
Path: /
RoleName: !Sub ${EnvironmentName}-ECSRole-${AWS::Region}
AssumeRolePolicyDocument: |
{
"Statement": [{
"Action": "sts:AssumeRole",
"Effect": "Allow",
"Principal": {
"Service": "ec2.amazonaws.com"
}
}]
}
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
Policies:
- PolicyName: ecs-service
PolicyDocument: |
{
"Statement": [{
"Effect": "Allow",
"Action": [
"ecs:CreateCluster",
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:StartTelemetrySession",
"ecs:Submit*",
"ecr:BatchCheckLayerAvailability",
"ecr:BatchGetImage",
"ecr:GetDownloadUrlForLayer",
"ecr:GetAuthorizationToken"
],
"Resource": "*"
}]
}
ECSInstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
InstanceProfileName: ECSInstanceProfile
Path: "/"
Roles:
- !Ref ECSRole
ECSServiceAutoScalingRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
Action:
- "sts:AssumeRole"
Effect: Allow
Principal:
Service:
- application-autoscaling.amazonaws.com
Path: /
Policies:
- PolicyName: ecs-service-autoscaling
PolicyDocument:
Statement:
Effect: Allow
Action:
- application-autoscaling:*
- cloudwatch:DescribeAlarms
- cloudwatch:PutMetricAlarm
- ecs:DescribeServices
- ecs:UpdateService
Resource: "*"
ECSCloudWatchParameter:
Type: AWS::SSM::Parameter
Properties:
Description: ECS
Name: !Sub "AmazonCloudWatch-${ECSCluster}-ECS"
Type: String
Value: !Sub |
{
"logs": {
"force_flush_interval": 5,
"logs_collected": {
"files": {
"collect_list": [
{
"file_path": "/var/log/messages",
"log_group_name": "${ECSCluster}-/var/log/messages",
"log_stream_name": "{instance_id}",
"timestamp_format": "%b %d %H:%M:%S"
},
{
"file_path": "/var/log/dmesg",
"log_group_name": "${ECSCluster}-/var/log/dmesg",
"log_stream_name": "{instance_id}"
},
{
"file_path": "/var/log/docker",
"log_group_name": "${ECSCluster}-/var/log/docker",
"log_stream_name": "{instance_id}",
"timestamp_format": "%Y-%m-%dT%H:%M:%S.%f"
},
{
"file_path": "/var/log/ecs/ecs-init.log",
"log_group_name": "${ECSCluster}-/var/log/ecs/ecs-init.log",
"log_stream_name": "{instance_id}",
"timestamp_format": "%Y-%m-%dT%H:%M:%SZ"
},
{
"file_path": "/var/log/ecs/ecs-agent.log.*",
"log_group_name": "${ECSCluster}-/var/log/ecs/ecs-agent.log",
"log_stream_name": "{instance_id}",
"timestamp_format": "%Y-%m-%dT%H:%M:%SZ"
},
{
"file_path": "/var/log/ecs/audit.log",
"log_group_name": "${ECSCluster}-/var/log/ecs/audit.log",
"log_stream_name": "{instance_id}",
"timestamp_format": "%Y-%m-%dT%H:%M:%SZ"
}
]
}
}
},
"metrics": {
"append_dimensions": {
"AutoScalingGroupName": "${!aws:AutoScalingGroupName}",
"InstanceId": "${!aws:InstanceId}",
"InstanceType": "${!aws:InstanceType}"
},
"metrics_collected": {
"collectd": {
"metrics_aggregation_interval": 60
},
"disk": {
"measurement": [
"used_percent"
],
"metrics_collection_interval": 60,
"resources": [
"/"
]
},
"mem": {
"measurement": [
"mem_used_percent"
],
"metrics_collection_interval": 60
},
"statsd": {
"metrics_aggregation_interval": 60,
"metrics_collection_interval": 10,
"service_address": ":8125"
}
}
}
}
ECSSecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Allows SSH to the instance.
GroupName: ECSSecurityGroup
VpcId: !Ref VPCID
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: 22
ToPort: 22
CidrIp: 0.0.0.0/0 #change the ip to your organization ip
SecurityGroupEgress:
- IpProtocol: -1
CidrIp: 0.0.0.0/0
ECSLaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Properties:
LaunchTemplateName: Customer-launch-template
LaunchTemplateData:
CreditSpecification:
CpuCredits: Unlimited
ImageId: !Ref ECSAMI
InstanceType: !Ref AMISize
IamInstanceProfile:
Arn: !GetAtt ECSInstanceProfile.Arn
UserData:
"Fn::Base64": !Sub |
#!/bin/bash
yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm
yum install -y https://s3.amazonaws.com/amazoncloudwatch-agent/amazon_linux/amd64/latest/amazon-cloudwatch-agent.rpm
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y aws-cfn-bootstrap hibagent
yum install -y ec2-instance-connect
/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource ECSLaunchTemplate
/opt/aws/bin/cfn-signal -e $? --region ${AWS::Region} --stack ${AWS::StackName} --resource ECSAutoScalingGroup
/usr/bin/enable-ec2-spot-hibernation
KeyName: !Ref EC2KeyPair
SecurityGroupIds:
- !Ref ECSSecurityGroup
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
collectd: []
commands:
01_add_instance_to_cluster:
command: !Sub echo ECS_CLUSTER=${ECSCluster} >> /etc/ecs/ecs.config
02_enable_cloudwatch_agent:
command: !Sub /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c ssm:${ECSCloudWatchParameter} -s
files:
/etc/cfn/cfn-hup.conf:
mode: 000400
owner: root
group: root
content: !Sub |
[main]
stack=${AWS::StackId}
region=${AWS::Region}
/etc/cfn/hooks.d/cfn-auto-reloader.conf:
content: !Sub |
[cfn-auto-reloader-hook]
triggers=post.update
path=Resources.ECSLaunchTemplate.Metadata.AWS::CloudFormation::Init
action=/opt/aws/bin/cfn-init -v --region ${AWS::Region} --stack ${AWS::StackName} --resource ECSLaunchTemplate
services:
sysvinit:
cfn-hup:
enabled: true
ensureRunning: true
files:
- /etc/cfn/cfn-hup.conf
- /etc/cfn/hooks.d/cfn-auto-reloader.conf
ECSAutoScalingGroup:
DependsOn: ECSCluster
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
VPCZoneIdentifier: !Ref Subnets
LaunchTemplate:
LaunchTemplateId: !Ref ECSLaunchTemplate
Version: !GetAtt ECSLaunchTemplate.LatestVersionNumber
MinSize: !Ref ClusterSize
MaxSize: !Ref ClusterMaxSize
DesiredCapacity: !Ref ClusterSize
Tags:
- Key: Name
Value: !Sub ${EnvironmentName} ECS host
PropagateAtLaunch: true
CreationPolicy:
ResourceSignal:
Timeout: PT15M
UpdatePolicy:
AutoScalingRollingUpdate:
MinInstancesInService: 1
MaxBatchSize: 1
PauseTime: PT15M
SuspendProcesses:
- HealthCheck
- ReplaceUnhealthy
- AZRebalance
- AlarmNotification
- ScheduledActions
WaitOnResourceSignals: true
ECSService:
Type: AWS::ECS::Service
Properties:
Cluster:
Ref: "ECSCluster"
DesiredCount: 0
TaskDefinition:
Ref: "ECSTaskDefinition"
CodeBuildServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
BuildRolePolicies:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: "AWSCodeBuildServiceRolePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/ECSProject
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/ECSProject:*
- Effect: "Allow"
Action:
- s3:GetObject
- s3:GetObjectVersion
- s3:PutObject
- s3:GetBucketAcl
- s3:GetBucketLocation
Resource: !Join [ '', [ !GetAtt CodePipelineArtifactStoreBucket.Arn, '/*' ] ]
- Effect: "Allow"
Action:
- codebuild:CreateReportGroup
- codebuild:CreateReport
- codebuild:UpdateReport
- codebuild:BatchPutTestCases
- codebuild:BatchPutCodeCoverages
Resource: !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/ECSProject-*"
Roles:
- Ref: "CodeBuildServiceRole"
CodeBuildInstanceProfile:
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles:
- Ref: "CodeBuildServiceRole"
CodePipelineServiceRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "codepipeline.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: "/"
RolePolicies:
Type: "AWS::IAM::Policy"
Properties:
PolicyName: "AWSCodePipelineServiceRolePolicy"
PolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Action: "iam:PassRole"
Resource: "*"
Condition:
StringEqualsIfExists:
iam:PassedToService:
- cloudformation.amazonaws.com
- elasticbeanstalk.amazonaws.com
- ec2.amazonaws.com
- ecs-tasks.amazonaws.com
- Effect: "Allow"
Action:
- codecommit:CancelUploadArchive
- codecommit:GetBranch
- codecommit:GetCommit
- codecommit:GetRepository
- codecommit:GetUploadArchiveStatus
- codecommit:UploadArchive
Resource: "*"
- Effect: "Allow"
Action:
- codedeploy:CreateDeployment
- codedeploy:GetApplication
- codedeploy:GetApplicationRevision
- codedeploy:GetDeployment
- codedeploy:GetDeploymentConfig
- codedeploy:RegisterApplicationRevision
Resource: "*"
- Effect: "Allow"
Action: codestar-connections:UseConnection
Resource: "*"
- Effect: "Allow"
Action:
- elasticbeanstalk:*
- ec2:*
- elasticloadbalancing:*
- autoscaling:*
- cloudwatch:*
- s3:*
- sns:*
- cloudformation:*
- rds:*
- sqs:*
- ecs:*
Resource: "*"
- Effect: "Allow"
Action:
- lambda:InvokeFunction
- lambda:ListFunctions
Resource: "*"
- Effect: "Allow"
Action:
- opsworks:CreateDeployment
- opsworks:DescribeApps
- opsworks:DescribeCommands
- opsworks:DescribeDeployments
- opsworks:DescribeInstances
- opsworks:DescribeStacks
- opsworks:UpdateApp
- opsworks:UpdateStack
Resource: "*"
- Effect: "Allow"
Action:
- cloudformation:CreateStack
- cloudformation:DeleteStack
- cloudformation:DescribeStacks
- cloudformation:UpdateStack
- cloudformation:CreateChangeSet
- cloudformation:DeleteChangeSet
- cloudformation:DescribeChangeSet
- cloudformation:ExecuteChangeSet
- cloudformation:SetStackPolicy
- cloudformation:ValidateTemplate
Resource: "*"
- Effect: "Allow"
Action:
- codebuild:BatchGetBuilds
- codebuild:StartBuild
- codebuild:BatchGetBuildBatches
- codebuild:StartBuildBatch
Resource: "*"
- Effect: "Allow"
Action:
- devicefarm:ListProjects
- devicefarm:ListDevicePools
- devicefarm:GetRun
- devicefarm:GetUpload
- devicefarm:CreateUpload
- devicefarm:ScheduleRun
Resource: "*"
- Effect: "Allow"
Action:
- servicecatalog:ListProvisioningArtifacts
- servicecatalog:CreateProvisioningArtifact
- servicecatalog:DescribeProvisioningArtifact
- servicecatalog:DeleteProvisioningArtifact
- servicecatalog:UpdateProduct
Resource: "*"
- Effect: "Allow"
Action: cloudformation:ValidateTemplate
Resource: "*"
- Effect: "Allow"
Action: ecr:DescribeImages
Resource: "*"
- Effect: "Allow"
Action:
- states:DescribeExecution
- states:DescribeStateMachine
- states:StartExecution
Resource: "*"
- Effect: "Allow"
Action:
- appconfig:StartDeployment
- appconfig:StopDeployment
- appconfig:GetDeployment
Resource: "*"
Roles:
- Ref: "CodePipelineServiceRole"
CodePipeLineInstanceProfile:
Type: "AWS::IAM::InstanceProfile"
Properties:
Path: "/"
Roles:
- Ref: "CodePipelineServiceRole"
AmazonCloudWatchEventRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Principal:
Service:
- events.amazonaws.com
Action: sts:AssumeRole
Path: /
Policies:
-
PolicyName: cwe-pipeline-execution
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action: codepipeline:StartPipelineExecution
Resource: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${ECSCodePipeLine}
AmazonCloudWatchEventRule:
Type: 'AWS::Events::Rule'
Properties:
EventPattern:
detail:
action-type: [PUSH]
image-tag: [latest]
repository-name: [!Ref ECRRepo]
result: [SUCCESS]
detail-type: [ECR Image Action]
source: [aws.ecr]
Targets:
- Arn: !Sub arn:aws:codepipeline:${AWS::Region}:${AWS::AccountId}:${ECSCodePipeLine}
RoleArn: !GetAtt
- AmazonCloudWatchEventRole
- Arn
Id: codepipeline-AppPipeline
CodePipelineArtifactStoreBucket:
Type: AWS::S3::Bucket
CodePipelineArtifactStoreBucketPolicy:
Type: AWS::S3::BucketPolicy
Properties:
Bucket: !Ref CodePipelineArtifactStoreBucket
PolicyDocument:
Version: 2012-10-17
Statement:
-
Sid: DenyUnEncryptedObjectUploads
Effect: Deny
Principal: '*'
Action: s3:PutObject
Resource: !Join [ '', [ !GetAtt CodePipelineArtifactStoreBucket.Arn, '/*' ] ]
Condition:
StringNotEquals:
s3:x-amz-server-side-encryption: aws:kms
-
Sid: DenyInsecureConnections
Effect: Deny
Principal: '*'
Action: s3:*
Resource: !Join [ '', [ !GetAtt CodePipelineArtifactStoreBucket.Arn, '/*' ] ]
Condition:
Bool:
aws:SecureTransport: false
ECSCodeBuild:
Type: AWS::CodeBuild::Project
Properties:
Name: ECSProject
Description: A build for ECR with ECS integration.
ServiceRole: !GetAtt CodeBuildServiceRole.Arn
Artifacts:
Type: no_artifacts
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/standard:5.0
Source:
Type: NO_SOURCE
BuildSpec: !Sub |
version: 0.2
phases:
install:
runtime-versions:
python: 3.9
build:
commands:
- apt-get install jq -y
- ContainerName="CustomerContainer"
- ImageURI=$(cat imageDetail.json | jq -r '.ImageURI')
- printf '[{"name":"CONTAINER_NAME","imageUri":"IMAGE_URI"}]' > imagedefinitions.json
- sed -i -e "s|CONTAINER_NAME|$ContainerName|g" imagedefinitions.json
- sed -i -e "s|IMAGE_URI|$ImageURI|g" imagedefinitions.json
- cat imagedefinitions.json
artifacts:
files:
- imagedefinitions.json
TimeoutInMinutes: 5
ECSCodePipeLine:
Type: AWS::CodePipeline::Pipeline
Properties:
RestartExecutionOnUpdate: true
RoleArn:
!GetAtt CodePipelineServiceRole.Arn
ArtifactStore:
Type: S3
Location: !Ref CodePipelineArtifactStoreBucket
Stages:
- Name: Source
Actions:
- Name: SourceAction
InputArtifacts: []
ActionTypeId:
Category: Source
Owner: AWS
Version: 1
Provider: ECR
OutputArtifacts:
- Name: SourceArtifact
RunOrder: 1
Configuration:
ImageTag: latest
RepositoryName: !Ref ECRRepo
- Name: Build
Actions:
- Name: ECSBuild
ActionTypeId:
Category: Build
Owner: AWS
Provider: CodeBuild
Version: '1'
RunOrder: 2
Configuration:
BatchEnabled: 'false'
CombineArtifacts: 'false'
ProjectName: ECSProject
PrimarySource: SourceArtifact
OutputArtifacts:
- Name: BuildArtifact
InputArtifacts:
- Name: SourceArtifact
- Name: Deploy
Actions:
- Name: DeployECS
ActionTypeId:
Category: Deploy
Owner: AWS
Provider: ECS
Version: '1'
RunOrder: 3
Configuration:
ClusterName: !Ref ECSCluster
ServiceName: !Ref ECSService
FileName: imagedefinitions.json
DeploymentTimeout: '15'
OutputArtifacts: []
InputArtifacts:
- Name: BuildArtifact
IAMUser:
Type: AWS::IAM::User
Properties:
UserName: !Ref IAMUserName
LoginProfile:
Password: !Ref TempPassword
PasswordResetRequired: true
IAMPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: Customer-Policy
Users:
- !Ref IAMUser
PolicyDocument:
Id: CustomerPolicy
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- iam:GetAccountPasswordPolicy
- iam:GetAccountSummary
- iam:ListUsers
- ecr:GetAuthorizationToken
- ecr:DescribeRepositories
- ec2:DescribeInstances
- ec2:DescribeImages
- ec2:DescribeTags
- ec2:DescribeSnapshots
Resource: '*'
- Effect: Allow
Action:
- ecr:ListImages
- ecr:BatchCheckLayerAvailability
- ecr:GetDownloadUrlForLayer
- ecr:GetRepositoryPolicy
- ecr:ListImages
- ecr:DescribeImages
- ecr:BatchGetImage
- ecr:InitiateLayerUpload
- ecr:UploadLayerPart
- ecr:CompleteLayerUpload
- ecr:PutImage
- ecr:BatchDeleteImage
Resource:
- !GetAtt ECRRepo.Arn
- Effect: Allow
Action:
- iam:ChangePassword
- iam:GetUser
- iam:CreateAccessKey
- iam:DeleteAccessKey
- iam:ListAccessKeys
- iam:UpdateAccessKey
- iam:CreateLoginProfile
- iam:DeleteLoginProfile
- iam:GetLoginProfile
- iam:UpdateLoginProfile
Resource:
- !GetAtt IAMUser.Arn
Outputs:
Cluster:
Description: A reference to the ECS cluster
Value: !Ref ECSCluster
ECSServiceAutoScalingRole:
Description: A reference to ECS service auto scaling role
Value: !GetAtt ECSServiceAutoScalingRole.Arn
ECSAutoScalingGroupName:
Description: A reference to ECS AutoScaling Group Name
Value: !Ref ECSAutoScalingGroup