forked from aws-samples/serverless-ui-testing-using-selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.yaml
941 lines (910 loc) · 31.6 KB
/
pipeline.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
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
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "AWS CloudFormation Template to deploy Serverless UI Testing (SUIT) pipeline"
Parameters:
RepositoryName:
Description: Enter the name of the CodeCommit repository
Type: String
Default: serverless-ui-testing
ApprovalEmail:
Description: Enter the email address to which approval notification needs to be sent
Type: String
Default: [email protected]
AllowedPattern: ^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$
ConstraintDescription: Ecpects a valid email address
Resources:
ApprovalTopic:
Type: AWS::SNS::Topic
Properties:
TopicName: !Sub ${AWS::StackName}-approval-topic
KmsMasterKeyId: alias/aws/sns
DisplayName: SUIT-Approval-Notification
Subscription:
- Endpoint: !Ref ApprovalEmail
Protocol: email
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: !Sub ${AWS::StackName}-approval-topic
TestOutputBucket:
Type: "AWS::S3::Bucket"
UpdateReplacePolicy: Retain
DeletionPolicy: Retain
Properties:
AccessControl: Private
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName: !Sub ${AWS::StackName}-test-output-${AWS::AccountId}-${AWS::Region}
VersioningConfiguration:
Status: Enabled
Tags:
- Key: Application
Value: !Ref AWS::StackId
CodePipelineArtifact:
Type: "AWS::S3::Bucket"
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
AccessControl: Private
BucketEncryption:
ServerSideEncryptionConfiguration:
- BucketKeyEnabled: true
ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName: !Sub ${AWS::StackName}-codepipeline-artifact-${AWS::AccountId}-${AWS::Region}
VersioningConfiguration:
Status: Enabled
Tags:
- Key: Application
Value: !Ref AWS::StackId
ECRRepository:
Type: AWS::ECR::Repository
DeletionPolicy: Retain
UpdateReplacePolicy: Retain
Properties:
RepositoryName: !Sub suit-${AWS::StackName}-repo
RepositoryPolicyText: |
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "LambdaECRImageRetrievalPolicy",
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": [
"ecr:BatchGetImage",
"ecr:DeleteRepositoryPolicy",
"ecr:GetDownloadUrlForLayer",
"ecr:GetRepositoryPolicy",
"ecr:SetRepositoryPolicy"
]
}
]
}
ModulesTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: ModId
AttributeType: S
KeySchema:
-
AttributeName: ModId
KeyType: HASH
BillingMode: PAY_PER_REQUEST
TableName: !Sub ModulesTable-${AWS::StackName}
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: !Sub ModulesTable-${AWS::StackName}
ModulesTableParameter:
Type: AWS::SSM::Parameter
Properties:
Name: ModulesTable
Type: String
Value: !Ref ModulesTable
Description: SSM Parameter for Modules Table.
TestOutputBucketParameter:
Type: AWS::SSM::Parameter
Properties:
Name: TestOutputBucket
Type: String
Value: !Ref TestOutputBucket
Description: SSM Parameter for Test Output Bucket
CodePipelineArtifactParameter:
Type: AWS::SSM::Parameter
Properties:
Name: CodePipelineArtifact
Type: String
Value: !Ref CodePipelineArtifact
Description: SSM Parameter for CodePipeline Artifact Bucket
SourceRepoParameter:
Type: AWS::SSM::Parameter
Properties:
Name: WebAppSourceRepo
Type: String
Value: !Ref RepositoryName
Description: SSM Parameter for Source Repository
StatusTable:
Type: AWS::DynamoDB::Table
Properties:
AttributeDefinitions:
-
AttributeName: testrunid
AttributeType: S
-
AttributeName: testcaseid
AttributeType: S
KeySchema:
-
AttributeName: testrunid
KeyType: HASH
-
AttributeName: testcaseid
KeyType: RANGE
BillingMode: PAY_PER_REQUEST
TableName: !Sub StatusTable-${AWS::StackName}
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: !Sub StatusTable-${AWS::StackName}
StatusTableParameter:
Type: AWS::SSM::Parameter
Properties:
Name: StatusTable
Type: String
Value: !Ref StatusTable
Description: SSM Parameter for Status Table.
StatusPageCognitoIP:
Type: AWS::Cognito::IdentityPool
Properties:
IdentityPoolName: !Sub StatusPageCognitoIP_${AWS::StackName}
AllowUnauthenticatedIdentities: true
StatusPageUnAuthRole:
Type: AWS::IAM::Role
Properties:
RoleName:
Fn::Sub: StatusPageUnAuthRole-${AWS::StackName}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Federated:
- "cognito-identity.amazonaws.com"
Action:
- "sts:AssumeRoleWithWebIdentity"
Condition:
StringEquals:
"cognito-identity.amazonaws.com:aud":
Ref: StatusPageCognitoIP
ForAnyValue:StringLike:
"cognito-identity.amazonaws.com:amr": unauthenticated
Path: /
Policies:
-
PolicyName:
Fn::Sub: StatusPageUnAuthRole-${AWS::StackName}-Policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "dynamodb:Query"
Resource:
- !GetAtt StatusTable.Arn
AttachCognitoUnAuthRole:
Type: "AWS::Cognito::IdentityPoolRoleAttachment"
Properties:
IdentityPoolId:
Ref: StatusPageCognitoIP
Roles:
unauthenticated: !GetAtt StatusPageUnAuthRole.Arn
AmplifyAccessRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub SUIT-${AWS::StackName}-AmplifyRole
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- amplify.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
-
PolicyName: !Sub SUIT-${AWS::StackName}-AmplifyRole-Policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "codecommit:GitPull"
Resource:
- !Sub arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:${RepositoryName}
-
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/amplify/*
TestApp:
Type: AWS::Amplify::App
Properties:
Name: TestAppWebsite
Repository: !Sub https://git-codecommit.${AWS::Region}.amazonaws.com/v1/repos/${RepositoryName}
BuildSpec: |
version: 1
applications:
- frontend:
phases:
build:
commands: []
artifacts:
baseDirectory: /
files:
- '**/*'
cache:
paths: []
appRoot: website
IAMServiceRole: !GetAtt AmplifyAccessRole.Arn
CustomRules:
- Target: /index.html
Source: "/<*>"
Status: "404-200"
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: TestAppWebsite
TestAppBranch:
Type: AWS::Amplify::Branch
Properties:
AppId: !GetAtt TestApp.AppId
BranchName: master
Description: Master branch for App
EnableAutoBuild: true
Stage: PRODUCTION
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: TestAppBranch
TestAppDomainParameter:
Type: AWS::SSM::Parameter
Properties:
Name: TestAppDomain
Type: String
Value: !GetAtt TestApp.DefaultDomain
Description: SSM Parameter for Test App Domain
StatusPage:
Type: AWS::Amplify::App
Properties:
Name: StatusPage
Repository: !Sub https://git-codecommit.${AWS::Region}.amazonaws.com/v1/repos/${RepositoryName}
BuildSpec: |
version: 1
applications:
- frontend:
phases:
build:
commands: []
artifacts:
baseDirectory: /
files:
- '**/*'
cache:
paths: []
appRoot: status
IAMServiceRole: !GetAtt AmplifyAccessRole.Arn
CustomRules:
- Target: /index.html
Source: "/<*>"
Status: "404-200"
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: StatusPage
StatusPageBranch:
Type: AWS::Amplify::Branch
Properties:
AppId: !GetAtt StatusPage.AppId
BranchName: master
Description: Master branch for Status
EnableAutoBuild: true
Stage: PRODUCTION
Tags:
- Key: Application
Value: !Ref AWS::StackId
- Key: Name
Value: StatusPageBranch
StatusPageDomainParameter:
Type: AWS::SSM::Parameter
Properties:
Name: StatusPageDomain
Type: String
Value: !GetAtt StatusPage.DefaultDomain
Description: SSM Parameter for Status Page Domain
CFNDeployRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub CFNDeployRole-${AWS::StackName}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "cloudformation.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: /
Policies:
-
PolicyName:
Fn::Sub: CFNDeployRole-${AWS::StackName}-Policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "ec2:AuthorizeSecurityGroupEgress"
- "ec2:AuthorizeSecurityGroupIngress"
- "ec2:DeleteSubnet"
- "ec2:ReplaceRouteTableAssociation"
- "ec2:DeleteRoute"
- "ec2:CreateVpc"
- "ec2:DeleteVpc"
- "ec2:CreateSecurityGroup"
- "ec2:DeleteSecurityGroup"
- "ec2:CreateRouteTable"
- "ec2:DeleteRouteTable"
- "ec2:AttachInternetGateway"
- "ec2:DetachInternetGateway"
- "ec2:DisassociateRouteTable"
- "ec2:AssociateRouteTable"
- "ec2:RevokeSecurityGroupIngress"
- "ec2:CreateRoute"
- "ec2:CreateInternetGateway"
- "ec2:RevokeSecurityGroupEgress"
- "ec2:CreateSubnet"
- "ec2:CreateTags"
- "ec2:DeleteTags"
- "ec2:ModifyVpcAttribute"
- "ec2:ModifySubnetAttribute"
- "ec2:UpdateSecurityGroupRuleDescriptionsEgress"
- "ec2:UpdateSecurityGroupRuleDescriptionsIngress"
Resource:
- !Sub arn:aws:ec2:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "iam:CreateInstanceProfile"
- "iam:DeleteInstanceProfile"
- "iam:GetRole"
- "iam:GetPolicy"
- "iam:RemoveRoleFromInstanceProfile"
- "iam:UpdateRoleDescription"
- "iam:CreateRole"
- "iam:DeleteRole"
- "iam:AddRoleToInstanceProfile"
- "iam:PassRole"
- "iam:CreateServiceLinkedRole"
- "iam:UpdateRole"
- "iam:DeleteServiceLinkedRole"
- "iam:GetRolePolicy"
- "iam:CreatePolicy"
- "iam:UpdateAssumeRolePolicy"
- "iam:DetachRolePolicy"
- "iam:DeleteRolePolicy"
- "iam:DeletePolicy"
- "iam:AttachRolePolicy"
- "iam:PutRolePolicy"
- "iam:CreatePolicyVersion"
- "iam:DeletePolicyVersion"
- "iam:TagRole"
- "iam:UntagRole"
- "iam:TagPolicy"
- "iam:UntagPolicy"
- "iam:TagInstanceProfile"
- "iam:UntagInstanceProfile"
Resource:
- Fn::Sub: arn:aws:iam::${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "lambda:CreateFunction"
- "lambda:UpdateFunctionEventInvokeConfig"
- "lambda:TagResource"
- "lambda:InvokeFunction"
- "lambda:GetFunction"
- "lambda:UpdateFunctionConfiguration"
- "lambda:UntagResource"
- "lambda:UpdateFunctionCode"
- "lambda:AddPermission"
- "lambda:PutFunctionEventInvokeConfig"
- "lambda:DeleteFunctionEventInvokeConfig"
- "lambda:DeleteFunction"
- "lambda:DeleteEventSourceMapping"
- "lambda:RemovePermission"
- "lambda:GetFunctionConfiguration"
- "lambda:ListTags"
Resource:
- !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:*
-
Effect: "Allow"
Action:
- "ecs:DescribeTaskDefinition"
- "ecs:DeleteCluster"
- "ecs:TagResource"
- "ecs:UntagResource"
Resource:
- !Sub arn:aws:ecs:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "codecommit:GetRepository"
- "codecommit:GetBranch"
- "codecommit:GetRepositoryTriggers"
- "codecommit:PutRepositoryTriggers"
- "codecommit:TestRepositoryTriggers"
- "codecommit:TagResource"
- "codecommit:UntagResource"
Resource:
- !Sub arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "logs:TagLogGroup"
- "logs:UntagLogGroup"
- "logs:DeleteLogGroup"
- "logs:DeleteRetentionPolicy"
- "logs:PutRetentionPolicy"
- "logs:CreateLogGroup"
Resource:
- !Sub arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:*
-
Effect: "Allow"
Action:
- "ecr:PutImage"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
- "ecr:InitiateLayerUpload"
- "ecr:BatchCheckLayerAvailability"
- "ecr:TagResource"
- "ecr:UntagResource"
Resource:
- !GetAtt ECRRepository.Arn
-
Effect: "Allow"
Action:
- "states:DeleteStateMachine"
- "states:UntagResource"
- "states:TagResource"
- "states:CreateStateMachine"
- "states:UpdateStateMachine"
Resource:
- !Sub arn:aws:states:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "ssm:GetParameters"
- "ssm:GetParameter"
- "ssm:PutParameter"
- "ssm:DeleteParameter"
- "ssm:DeleteParameters"
- "ssm:AddTagsToResource"
- "ssm:RemoveTagsFromResource"
Resource:
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/*
-
Effect: "Allow"
Action:
- "sns:CreateTopic"
- "sns:DeleteTopic"
- "sns:Subscribe"
- "sns:UnSubscribe"
- "sns:ListTopics"
Resource:
- !Sub arn:aws:sns:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "amplify:UntagResource"
- "amplify:DeleteBranch"
- "amplify:CreateDeployment"
- "amplify:CreateBranch"
- "amplify:UpdateBranch"
- "amplify:DeleteApp"
- "amplify:ListBranches"
- "amplify:GetBranch"
- "amplify:StartDeployment"
- "amplify:CreateApp"
- "amplify:TagResource"
- "amplify:GetApp"
- "amplify:UpdateApp"
Resource:
- !Sub arn:aws:amplify:${AWS::Region}:${AWS::AccountId}:*
-
Effect: "Allow"
Action:
- "ec2:DescribeInternetGateways"
- "ec2:DescribeVpcs"
- "ec2:DeleteInternetGateway"
- "ecs:CreateCluster"
- "ec2:DescribeSecurityGroups"
- "ec2:DescribeSecurityGroupReferences"
- "ec2:DescribeSubnets"
- "ec2:DescribeRouteTables"
- "ecs:DescribeClusters"
- "ecs:RegisterTaskDefinition"
- "ecs:DeregisterTaskDefinition"
- "ssm:DescribeParameters"
Resource:
- "*"
CodeBuildServiceRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Sub CodeBuildServiceRole-${AWS::StackName}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "codebuild.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: /
Policies:
-
PolicyName:
Fn::Sub: CodeBuildServiceRole-${AWS::StackName}-Policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "codecommit:ListBranches"
- "codecommit:ListRepositories"
- "codecommit:BatchGetRepositories"
- "codecommit:Get*"
- "codecommit:GitPull"
- "codecommit:GitPush"
Resource:
- !Sub arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:${RepositoryName}
-
Effect: "Allow"
Action:
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
Resource:
- Fn::Sub: arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/codebuild/*
-
Effect: "Allow"
Action:
- "s3:PutObject"
- "s3:GetObject"
- "s3:GetObjectVersion"
- "s3:ListBucket"
Resource:
- !Sub arn:aws:s3:::${AWS::StackName}-test-output-${AWS::AccountId}-${AWS::Region}/*
- !Sub arn:aws:s3:::${AWS::StackName}-test-output-${AWS::AccountId}-${AWS::Region}
- !Sub arn:aws:s3:::${AWS::StackName}-codepipeline-artifact-${AWS::AccountId}-${AWS::Region}/*
- !Sub arn:aws:s3:::${AWS::StackName}-codepipeline-artifact-${AWS::AccountId}-${AWS::Region}
- !Sub arn:aws:s3:::codepipeline-${AWS::Region}-*
-
Effect: "Allow"
Action:
- "amplify:StartJob"
Resource:
- !Sub arn:aws:amplify:${AWS::Region}:${AWS::AccountId}:apps/${TestApp.AppId}/branches/master/jobs/*
- !Sub arn:aws:amplify:${AWS::Region}:${AWS::AccountId}:apps/${StatusPage.AppId}/branches/master/jobs/*
-
Effect: "Allow"
Action:
- "ecr:PutImage"
- "ecr:UploadLayerPart"
- "ecr:CompleteLayerUpload"
- "ecr:InitiateLayerUpload"
- "ecr:BatchCheckLayerAvailability"
Resource:
- !GetAtt ECRRepository.Arn
-
Effect: "Allow"
Action:
- "iam:PassRole"
- "ecr:GetAuthorizationToken"
- "ssm:PutParameter"
Resource:
- "*"
BuildContainerProject:
Type: AWS::CodeBuild::Project
Properties:
Name: !Sub SUIT-${AWS::StackName}-BuildContainerProject
Description: Project to build containers and prepare the application
ServiceRole: !GetAtt [ CodeBuildServiceRole, Arn ]
Artifacts:
Type: CODEPIPELINE
Environment:
Type: LINUX_CONTAINER
ComputeType: BUILD_GENERAL1_SMALL
Image: aws/codebuild/amazonlinux2-x86_64-standard:3.0
PrivilegedMode: true
EnvironmentVariables:
- Name: AWS_ACCOUNT_ID
Value: !Ref AWS::AccountId
- Name: IMAGE_REPO_NAME
Value: !Ref ECRRepository
- Name: Cognito_IDP_ID
Value: !Ref StatusPageCognitoIP
- Name: RepositoryName
Value: !Ref RepositoryName
- Name: DDB_STATUS_TABLE
Value: !Ref StatusTable
Source:
Type: CODEPIPELINE
TimeoutInMinutes: 15
Cache:
Type: LOCAL
Modes:
- LOCAL_DOCKER_LAYER_CACHE
Tags:
- Key: Name
Value: !Sub SUIT-${AWS::StackName}-BuildContainerProject
CodePipelineRole:
Type: "AWS::IAM::Role"
Properties:
RoleName: !Sub SUIT-CodePipelineRole-${AWS::StackName}
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Principal:
Service:
- "codepipeline.amazonaws.com"
Action:
- "sts:AssumeRole"
Path: /
Policies:
-
PolicyName: !Sub SUIT-CodePipelineRole-${AWS::StackName}-Policy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: "Allow"
Action:
- "s3:DeleteObject"
- "s3:GetObject"
- "s3:GetObjectVersion"
- "s3:ListBucket"
- "s3:PutObject"
- "s3:GetBucketPolicy"
Resource:
- !Sub arn:aws:s3:::${CodePipelineArtifact}
- !Sub arn:aws:s3:::${CodePipelineArtifact}/*
-
Effect: "Allow"
Action:
- "codecommit:ListBranches"
- "codecommit:ListRepositories"
- "codecommit:BatchGetRepositories"
- "codecommit:Get*"
- "codecommit:GitPull"
- "codecommit:UploadArchive"
Resource:
- !Sub arn:aws:codecommit:${AWS::Region}:${AWS::AccountId}:${RepositoryName}
-
Effect: "Allow"
Action:
- "codebuild:StartBuild"
- "codebuild:BatchGetBuilds"
Resource:
- !GetAtt BuildContainerProject.Arn
- !Sub ${BuildContainerProject.Arn}:*
-
Effect: "Allow"
Action:
- "cloudformation:ListStacks"
- "cloudformation:CancelUpdateStack"
- "cloudformation:DescribeStackResources"
- "cloudformation:DescribeStackResource"
- "cloudformation:CreateChangeSet"
- "cloudformation:DeleteChangeSet"
- "cloudformation:DescribeStacks"
- "cloudformation:ContinueUpdateRollback"
- "cloudformation:CreateStack"
- "cloudformation:DeleteStack"
- "cloudformation:UpdateStack"
- "cloudformation:DescribeChangeSet"
- "cloudformation:ExecuteChangeSet"
- "cloudformation:ValidateTemplate"
- "cloudformation:ListChangeSets"
Resource:
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/*
-
Effect: "Allow"
Action:
- "states:StartExecution"
- "states:DescribeActivity"
- "states:DescribeStateMachine"
- "states:DescribeExecution"
- "states:CreateActivity"
- "states:GetExecutionHistory"
- "states:StartExecution"
- "states:DeleteActivity"
- "states:StopExecution"
- "states:GetActivityTask"
Resource:
- !Sub arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:SUIT-*
- !Sub arn:aws:states:${AWS::Region}:${AWS::AccountId}:execution:SUIT-*
-
Effect: "Allow"
Action:
- "sns:Publish"
Resource:
- !Ref ApprovalTopic
-
Effect: "Allow"
Action:
- "iam:PassRole"
Resource:
- "*"
ServerlessUITestPipeline:
Type: "AWS::CodePipeline::Pipeline"
Properties:
Name: !Sub ServerlessUITestPipeline-${AWS::StackName}
RoleArn: !GetAtt [ CodePipelineRole, Arn ]
Stages:
-
Name: Source
Actions:
-
Name: SUITestSource
ActionTypeId:
Category: Source
Owner: AWS
Version: "1"
Provider: CodeCommit
OutputArtifacts:
-
Name: SUITestSourceOutput
Configuration:
BranchName: master
RepositoryName: !Ref RepositoryName
RunOrder: 1
-
Name: Build
Actions:
-
Name: BuildContainer
InputArtifacts:
- Name: SUITestSourceOutput
ActionTypeId:
Category: Build
Owner: AWS
Version: "1"
Provider: CodeBuild
OutputArtifacts:
-
Name: BuildContainerArtifact
Configuration:
ProjectName: !Ref BuildContainerProject
RunOrder: 1
-
Name: Test
Actions:
-
Name: DeployTestEnv
ActionTypeId:
Category: Deploy
Owner: AWS
Version: "1"
Provider: CloudFormation
InputArtifacts:
- Name: SUITestSourceOutput
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_NAMED_IAM
RoleArn: !GetAtt CFNDeployRole.Arn
StackName: !Sub SUIT-Test-Stack-${AWS::StackName}
TemplatePath: SUITestSourceOutput::deployment.yaml
OutputArtifacts:
-
Name: TestEnvDeploy
Region: !Ref AWS::Region
RunOrder: 1
-
Name: Run-Mod1-Test
Namespace: TestVariables
ActionTypeId:
Category: Invoke
Owner: AWS
Version: "1"
Provider: StepFunctions
InputArtifacts:
- Name: TestEnvDeploy
Configuration:
ExecutionNamePrefix: suit
Input: '{"DDBKey":{"ModId":{"S":"mod1"}}}'
StateMachineArn: !Sub arn:aws:states:${AWS::Region}:${AWS::AccountId}:stateMachine:SUIT-StateMachine
OutputArtifacts:
-
Name: Mod1TestOut
Region: !Ref AWS::Region
RunOrder: 2
-
Name: Approval
Actions:
-
Name: DeployApproval
ActionTypeId:
Category: Approval
Owner: AWS
Version: "1"
Provider: Manual
Configuration:
NotificationArn: !Ref ApprovalTopic
ExternalEntityLink: !Sub https://master.${StatusPage.DefaultDomain}/?earn=#{TestVariables.ExecutionArn}
CustomData: Approve production deployment after validating the test status.
RunOrder: 1
-
Name: ProdDeploy
Actions:
-
Name: DeployProd
ActionTypeId:
Category: Deploy
Owner: AWS
Version: "1"
Provider: CloudFormation
InputArtifacts:
- Name: SUITestSourceOutput
Configuration:
ActionMode: CREATE_UPDATE
Capabilities: CAPABILITY_NAMED_IAM
RoleArn: !GetAtt CFNDeployRole.Arn
StackName: !Sub SUIT-Prod-Stack-${AWS::StackName}
TemplatePath: SUITestSourceOutput::prod-deploy.yaml
OutputArtifacts:
-
Name: ProdDeploy
Region: !Ref AWS::Region
RunOrder: 1
ArtifactStore:
Type: S3
Location:
Ref: CodePipelineArtifact
Outputs:
TestWebsite:
Description: "URL of Test Website"
Value: !Sub https://master.${TestApp.DefaultDomain}
StatusWebsite:
Description: "URL of Status Website"
Value: !Sub https://master.${StatusPage.DefaultDomain}