-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathtemplate-with-defaultvpc-flowlogs.yml
More file actions
1291 lines (1274 loc) · 44.4 KB
/
template-with-defaultvpc-flowlogs.yml
File metadata and controls
1291 lines (1274 loc) · 44.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
Description: CloudFormation environment template for infrastructure shared among Copilot workloads.
Metadata:
Manifest: |
name: test
type: Environment
network:
vpc:
flow_logs:
retention: 60
Parameters:
AppName:
Type: String
EnvironmentName:
Type: String
ALBWorkloads:
Type: String
InternalALBWorkloads:
Type: String
EFSWorkloads:
Type: String
NATWorkloads:
Type: String
AppRunnerPrivateWorkloads:
Type: String
ToolsAccountPrincipalARN:
Type: String
AppDNSName:
Type: String
AppDNSDelegationRole:
Type: String
Aliases:
Type: String
CreateHTTPSListener:
Type: String
AllowedValues: [true, false]
CreateInternalHTTPSListener:
Type: String
AllowedValues: [true, false]
ServiceDiscoveryEndpoint:
Type: String
Conditions:
CreateALB:
!Not [!Equals [ !Ref ALBWorkloads, "" ]]
CreateInternalALB:
!Not [!Equals [ !Ref InternalALBWorkloads, "" ]]
DelegateDNS:
!Not [!Equals [ !Ref AppDNSName, "" ]]
ExportHTTPSListener: !And
- !Condition CreateALB
- !Equals [ !Ref CreateHTTPSListener, true ]
ExportInternalHTTPSListener: !And
- !Condition CreateInternalALB
- !Equals [ !Ref CreateInternalHTTPSListener, true ]
CreateEFS:
!Not [!Equals [ !Ref EFSWorkloads, ""]]
CreateNATGateways:
!Not [!Equals [ !Ref NATWorkloads, ""]]
CreateAppRunnerVPCEndpoint:
!Not [!Equals [ !Ref AppRunnerPrivateWorkloads, ""]]
ManagedAliases: !And
- !Condition DelegateDNS
- !Not [!Equals [ !Ref Aliases, "" ]]
- !Condition CreateALB
Resources:
# The CloudformationExecutionRole definition must be immediately followed with DeletionPolicy: Retain.
# See #1533.
CloudformationExecutionRole:
Metadata:
'aws:copilot:description': 'An IAM Role for AWS CloudFormation to manage resources'
DeletionPolicy: Retain
Type: AWS::IAM::Role
Properties:
RoleName: !Sub ${AWS::StackName}-CFNExecutionRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- 'cloudformation.amazonaws.com'
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: executeCfn
# This policy is more permissive than the managed PowerUserAccess
# since it allows arbitrary role creation, which is needed for the
# ECS task role specified by the customers.
PolicyDocument:
Version: '2012-10-17'
Statement:
-
Effect: Allow
NotAction:
- 'organizations:*'
- 'account:*'
Resource: '*'
-
Effect: Allow
Action:
- 'organizations:DescribeOrganization'
- 'account:ListRegions'
Resource: '*'
EnvironmentManagerRole:
Metadata:
'aws:copilot:description': 'An IAM Role to describe resources in your environment'
DeletionPolicy: Retain
Type: AWS::IAM::Role
DependsOn: CloudformationExecutionRole
Properties:
RoleName: !Sub ${AWS::StackName}-EnvManagerRole
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
AWS: !Sub ${ToolsAccountPrincipalARN}
Action: sts:AssumeRole
Path: /
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Sid: CloudwatchLogs
Effect: Allow
Action: [
"logs:GetLogRecord",
"logs:GetQueryResults",
"logs:StartQuery",
"logs:GetLogEvents",
"logs:DescribeLogStreams",
"logs:StopQuery",
"logs:TestMetricFilter",
"logs:FilterLogEvents",
"logs:GetLogGroupFields",
"logs:GetLogDelivery"
]
Resource: "*"
- Sid: Cloudwatch
Effect: Allow
Action: [
"cloudwatch:DescribeAlarms"
]
Resource: "*"
- Sid: ECS
Effect: Allow
Action: [
"ecs:ListAttributes",
"ecs:ListTasks",
"ecs:DescribeServices",
"ecs:DescribeTaskSets",
"ecs:ListContainerInstances",
"ecs:DescribeContainerInstances",
"ecs:DescribeTasks",
"ecs:DescribeClusters",
"ecs:UpdateService",
"ecs:PutAttributes",
"ecs:StartTelemetrySession",
"ecs:StartTask",
"ecs:StopTask",
"ecs:ListServices",
"ecs:ListTaskDefinitionFamilies",
"ecs:DescribeTaskDefinition",
"ecs:ListTaskDefinitions",
"ecs:ListClusters",
"ecs:RunTask",
"ecs:ListServicesByNamespace"
]
Resource: "*"
- Sid: ExecuteCommand
Effect: Allow
Action: [
"ecs:ExecuteCommand",
"ssm:StartSession"
]
Resource: "*"
Condition:
StringEquals:
'aws:ResourceTag/copilot-application': !Sub '${AppName}'
'aws:ResourceTag/copilot-environment': !Sub '${EnvironmentName}'
- Sid: StartStateMachine
Effect: Allow
Action:
- "states:StartExecution"
- "states:DescribeStateMachine"
Resource:
- !Sub "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${AppName}-${EnvironmentName}-*"
- Sid: CloudFormation
Effect: Allow
Action: [
"cloudformation:CancelUpdateStack",
"cloudformation:CreateChangeSet",
"cloudformation:CreateStack",
"cloudformation:DeleteChangeSet",
"cloudformation:DeleteStack",
"cloudformation:Describe*",
"cloudformation:DetectStackDrift",
"cloudformation:DetectStackResourceDrift",
"cloudformation:ExecuteChangeSet",
"cloudformation:GetTemplate",
"cloudformation:GetTemplateSummary",
"cloudformation:UpdateStack",
"cloudformation:UpdateTerminationProtection"
]
Resource: "*"
- Sid: GetAndPassCopilotRoles
Effect: Allow
Action: [
"iam:GetRole",
"iam:PassRole"
]
Resource: "*"
Condition:
StringEquals:
'iam:ResourceTag/copilot-application': !Sub '${AppName}'
'iam:ResourceTag/copilot-environment': !Sub '${EnvironmentName}'
- Sid: ECR
Effect: Allow
Action: [
"ecr:BatchGetImage",
"ecr:BatchCheckLayerAvailability",
"ecr:CompleteLayerUpload",
"ecr:DescribeImages",
"ecr:DescribeRepositories",
"ecr:GetDownloadUrlForLayer",
"ecr:InitiateLayerUpload",
"ecr:ListImages",
"ecr:ListTagsForResource",
"ecr:PutImage",
"ecr:UploadLayerPart",
"ecr:GetAuthorizationToken"
]
Resource: "*"
- Sid: ResourceGroups
Effect: Allow
Action: [
"resource-groups:GetGroup",
"resource-groups:GetGroupQuery",
"resource-groups:GetTags",
"resource-groups:ListGroupResources",
"resource-groups:ListGroups",
"resource-groups:SearchResources"
]
Resource: "*"
- Sid: SSM
Effect: Allow
Action: [
"ssm:DeleteParameter",
"ssm:DeleteParameters",
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParametersByPath"
]
Resource: "*"
- Sid: SSMSecret
Effect: Allow
Action: [
"ssm:PutParameter",
"ssm:AddTagsToResource"
]
Resource:
- !Sub 'arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/copilot/${AppName}/${EnvironmentName}/secrets/*'
- Sid: SSMSession
Effect: Allow
Action:
- ssm:StartSession
Resource:
- !Sub "arn:${AWS::Partition}:ssm:${AWS::Region}::document/AWS-StartPortForwardingSessionToRemoteHost"
- Sid: ELBv2
Effect: Allow
Action: [
"elasticloadbalancing:DescribeLoadBalancerAttributes",
"elasticloadbalancing:DescribeSSLPolicies",
"elasticloadbalancing:DescribeLoadBalancers",
"elasticloadbalancing:DescribeTargetGroupAttributes",
"elasticloadbalancing:DescribeListeners",
"elasticloadbalancing:DescribeTags",
"elasticloadbalancing:DescribeTargetHealth",
"elasticloadbalancing:DescribeTargetGroups",
"elasticloadbalancing:DescribeRules"
]
Resource: "*"
- Sid: BuiltArtifactAccess
Effect: Allow
Action: [
"s3:ListBucketByTags",
"s3:GetLifecycleConfiguration",
"s3:GetBucketTagging",
"s3:GetInventoryConfiguration",
"s3:GetObjectVersionTagging",
"s3:ListBucketVersions",
"s3:GetBucketLogging",
"s3:ListBucket",
"s3:GetAccelerateConfiguration",
"s3:GetBucketPolicy",
"s3:GetObjectVersionTorrent",
"s3:GetObjectAcl",
"s3:GetEncryptionConfiguration",
"s3:GetBucketRequestPayment",
"s3:GetObjectVersionAcl",
"s3:GetObjectTagging",
"s3:GetMetricsConfiguration",
"s3:HeadBucket",
"s3:GetBucketPublicAccessBlock",
"s3:GetBucketPolicyStatus",
"s3:ListBucketMultipartUploads",
"s3:GetBucketWebsite",
"s3:ListJobs",
"s3:GetBucketVersioning",
"s3:GetBucketAcl",
"s3:GetBucketNotification",
"s3:GetReplicationConfiguration",
"s3:ListMultipartUploadParts",
"s3:GetObject",
"s3:GetObjectTorrent",
"s3:GetAccountPublicAccessBlock",
"s3:ListAllMyBuckets",
"s3:DescribeJob",
"s3:GetBucketCORS",
"s3:GetAnalyticsConfiguration",
"s3:GetObjectVersionForReplication",
"s3:GetBucketLocation",
"s3:GetObjectVersion",
"kms:Decrypt"
]
Resource: "*"
- Sid: PutObjectsToArtifactBucket
Effect: Allow
Action:
- s3:PutObject
- s3:PutObjectAcl
Resource:
- arn:aws:s3:::mockbucket
- arn:aws:s3:::mockbucket/*
- Sid: EncryptObjectsInArtifactBucket
Effect: Allow
Action:
- kms:GenerateDataKey
Resource: arn:aws:kms:us-west-2:000000000:key/1234abcd-12ab-34cd-56ef-1234567890ab
- Sid: EC2
Effect: Allow
Action: [
"ec2:DescribeSubnets",
"ec2:DescribeSecurityGroups",
"ec2:DescribeNetworkInterfaces",
"ec2:DescribeRouteTables"
]
Resource: "*"
- Sid: AppRunner
Effect: Allow
Action: [
"apprunner:DescribeService",
"apprunner:ListOperations",
"apprunner:ListServices",
"apprunner:PauseService",
"apprunner:ResumeService",
"apprunner:StartDeployment",
"apprunner:DescribeObservabilityConfiguration",
"apprunner:DescribeVpcIngressConnection"
]
Resource: "*"
- Sid: Tags
Effect: Allow
Action: [
"tag:GetResources"
]
Resource: "*"
- Sid: ApplicationAutoscaling
Effect: Allow
Action: [
"application-autoscaling:DescribeScalingPolicies"
]
Resource: "*"
- Sid: DeleteRoles
Effect: Allow
Action: [
"iam:DeleteRole",
"iam:ListRolePolicies",
"iam:DeleteRolePolicy"
]
Resource:
- !GetAtt CloudformationExecutionRole.Arn
- !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${AWS::StackName}-EnvManagerRole"
- Sid: DeleteEnvStack
Effect: Allow
Action:
- 'cloudformation:DescribeStacks'
- 'cloudformation:DeleteStack'
Resource:
- !Sub 'arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}/*'
- Sid: ListStacks
Effect: Allow
Action:
- 'cloudformation:ListStacks'
Resource: "*"
- Sid: RDS
Effect: Allow
Action:
- 'rds:DescribeDBInstances'
- 'rds:DescribeDBClusters'
Resource: "*"
VPC:
Metadata:
'aws:copilot:description': 'A Virtual Private Cloud to control networking of your AWS resources'
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsHostnames: true
EnableDnsSupport: true
InstanceTenancy: default
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}'
PublicRouteTable:
Metadata:
'aws:copilot:description': "A custom route table that directs network traffic for the public subnets"
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}'
DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
InternetGateway:
Metadata:
'aws:copilot:description': 'An Internet Gateway to connect to the public internet'
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}'
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
PublicSubnet1:
Metadata:
'aws:copilot:description': 'Public subnet 1 for resources that can access the internet'
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.0.0/24
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-pub0'
PublicSubnet2:
Metadata:
'aws:copilot:description': 'Public subnet 2 for resources that can access the internet'
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.1.0/24
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-pub1'
PrivateSubnet1:
Metadata:
'aws:copilot:description': 'Private subnet 1 for resources with no internet access'
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.2.0/24
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-priv0'
PrivateSubnet2:
Metadata:
'aws:copilot:description': 'Private subnet 2 for resources with no internet access'
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.3.0/24
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-priv1'
PublicSubnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet1
PublicSubnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref PublicSubnet2
NatGateway1Attachment:
Metadata:
'aws:copilot:description': 'An Elastic IP for NAT Gateway 1'
Type: AWS::EC2::EIP
Condition: CreateNATGateways
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
NatGateway1:
Metadata:
'aws:copilot:description': 'NAT Gateway 1 enabling workloads placed in private subnet 1 to reach the internet'
Type: AWS::EC2::NatGateway
Condition: CreateNATGateways
Properties:
AllocationId: !GetAtt NatGateway1Attachment.AllocationId
SubnetId: !Ref PublicSubnet1
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-0'
PrivateRouteTable1:
Type: AWS::EC2::RouteTable
Condition: CreateNATGateways
Properties:
VpcId: !Ref 'VPC'
PrivateRoute1:
Type: AWS::EC2::Route
Condition: CreateNATGateways
Properties:
RouteTableId: !Ref PrivateRouteTable1
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway1
PrivateRouteTable1Association:
Type: AWS::EC2::SubnetRouteTableAssociation
Condition: CreateNATGateways
Properties:
RouteTableId: !Ref PrivateRouteTable1
SubnetId: !Ref PrivateSubnet1
NatGateway2Attachment:
Metadata:
'aws:copilot:description': 'An Elastic IP for NAT Gateway 2'
Type: AWS::EC2::EIP
Condition: CreateNATGateways
DependsOn: InternetGatewayAttachment
Properties:
Domain: vpc
NatGateway2:
Metadata:
'aws:copilot:description': 'NAT Gateway 2 enabling workloads placed in private subnet 2 to reach the internet'
Type: AWS::EC2::NatGateway
Condition: CreateNATGateways
Properties:
AllocationId: !GetAtt NatGateway2Attachment.AllocationId
SubnetId: !Ref PublicSubnet2
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-1'
PrivateRouteTable2:
Type: AWS::EC2::RouteTable
Condition: CreateNATGateways
Properties:
VpcId: !Ref 'VPC'
PrivateRoute2:
Type: AWS::EC2::Route
Condition: CreateNATGateways
Properties:
RouteTableId: !Ref PrivateRouteTable2
DestinationCidrBlock: 0.0.0.0/0
NatGatewayId: !Ref NatGateway2
PrivateRouteTable2Association:
Type: AWS::EC2::SubnetRouteTableAssociation
Condition: CreateNATGateways
Properties:
RouteTableId: !Ref PrivateRouteTable2
SubnetId: !Ref PrivateSubnet2
# Creates a service discovery namespace with the form provided in the parameter.
# For new environments after 1.5.0, this is "env.app.local". For upgraded environments from
# before 1.5.0, this is app.local.
ServiceDiscoveryNamespace:
Metadata:
'aws:copilot:description': 'A private DNS namespace for discovering services within the environment'
Type: AWS::ServiceDiscovery::PrivateDnsNamespace
Properties:
Name: !Ref ServiceDiscoveryEndpoint
Vpc: !Ref VPC
Cluster:
Metadata:
'aws:copilot:description': 'An ECS cluster to group your services'
Type: AWS::ECS::Cluster
Properties:
CapacityProviders: ['FARGATE', 'FARGATE_SPOT']
Configuration:
ExecuteCommandConfiguration:
Logging: DEFAULT
ClusterSettings:
- Name: containerInsights
Value: disabled
PublicHTTPLoadBalancerSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group for your load balancer allowing HTTP traffic'
Condition: CreateALB
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: HTTP access to the public facing load balancer
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: Allow from anyone on port 80
FromPort: 80
IpProtocol: tcp
ToPort: 80
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-lb-http'
PublicHTTPSLoadBalancerSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group for your load balancer allowing HTTPS traffic'
Condition: ExportHTTPSListener
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: HTTPS access to the public facing load balancer
SecurityGroupIngress:
- CidrIp: 0.0.0.0/0
Description: Allow from anyone on port 443
FromPort: 443
IpProtocol: tcp
ToPort: 443
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-lb-https'
InternalLoadBalancerSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group for your internal load balancer allowing HTTP traffic from within the VPC'
Condition: CreateInternalALB
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Access to the internal load balancer
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-internal-lb'
# Only accept requests coming from the public ALB, internal ALB, or other containers in the same security group.
EnvironmentSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group to allow your containers to talk to each other'
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: !Join ['', [!Ref AppName, '-', !Ref EnvironmentName, EnvironmentSecurityGroup]]
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-env'
EnvironmentHTTPSecurityGroupIngressFromPublicALB:
Type: AWS::EC2::SecurityGroupIngress
Condition: CreateALB
Properties:
Description: HTTP ingress from the public ALB
GroupId: !Ref EnvironmentSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref PublicHTTPLoadBalancerSecurityGroup
EnvironmentHTTPSSecurityGroupIngressFromPublicALB:
Type: AWS::EC2::SecurityGroupIngress
Condition: ExportHTTPSListener
Properties:
Description: HTTPS ingress from the public ALB
GroupId: !Ref EnvironmentSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref PublicHTTPSLoadBalancerSecurityGroup
EnvironmentSecurityGroupIngressFromInternalALB:
Type: AWS::EC2::SecurityGroupIngress
Condition: CreateInternalALB
Properties:
Description: Ingress from the internal ALB
GroupId: !Ref EnvironmentSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref InternalLoadBalancerSecurityGroup
EnvironmentSecurityGroupIngressFromSelf:
Type: AWS::EC2::SecurityGroupIngress
Properties:
Description: Ingress from other containers in the same security group
GroupId: !Ref EnvironmentSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref EnvironmentSecurityGroup
InternalALBIngressFromEnvironmentSecurityGroup:
Type: AWS::EC2::SecurityGroupIngress
Condition: CreateInternalALB
Properties:
Description: Ingress from the env security group
GroupId: !Ref InternalLoadBalancerSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref EnvironmentSecurityGroup
PublicLoadBalancer:
Metadata:
'aws:copilot:description': 'An Application Load Balancer to distribute public traffic to your services'
Condition: CreateALB
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
LoadBalancerAttributes:
- Key: 'access_logs.s3.enabled'
Value: false
Scheme: internet-facing
SecurityGroups:
- !GetAtt PublicHTTPLoadBalancerSecurityGroup.GroupId
- !If [ExportHTTPSListener, !GetAtt PublicHTTPSLoadBalancerSecurityGroup.GroupId, !Ref "AWS::NoValue"]
Subnets: [ !Ref PublicSubnet1, !Ref PublicSubnet2, ]
Type: application
# Assign a dummy target group that with no real services as targets, so that we can create
# the listeners for the services.
DefaultHTTPTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Condition: CreateALB
Properties:
# Check if your application is healthy within 20 = 10*2 seconds, compared to 2.5 mins = 30*5 seconds.
HealthCheckIntervalSeconds: 10 # Default is 30.
HealthyThresholdCount: 2 # Default is 5.
HealthCheckTimeoutSeconds: 5
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60 # Default is 300.
TargetType: ip
VpcId: !Ref VPC
HTTPListener:
Metadata:
'aws:copilot:description': 'A load balancer listener to route HTTP traffic'
Type: AWS::ElasticLoadBalancingV2::Listener
Condition: CreateALB
Properties:
DefaultActions:
- TargetGroupArn: !Ref DefaultHTTPTargetGroup
Type: forward
LoadBalancerArn: !Ref PublicLoadBalancer
Port: 80
Protocol: HTTP
HTTPSListener:
Metadata:
'aws:copilot:description': 'A load balancer listener to route HTTPS traffic'
Type: AWS::ElasticLoadBalancingV2::Listener
Condition: ExportHTTPSListener
Properties:
Certificates:
- CertificateArn: !Ref HTTPSCert
DefaultActions:
- TargetGroupArn: !Ref DefaultHTTPTargetGroup
Type: forward
LoadBalancerArn: !Ref PublicLoadBalancer
Port: 443
Protocol: HTTPS
InternalLoadBalancer:
Metadata:
'aws:copilot:description': 'An internal Application Load Balancer to distribute private traffic from within the VPC to your services'
Condition: CreateInternalALB
Type: AWS::ElasticLoadBalancingV2::LoadBalancer
Properties:
Scheme: internal
SecurityGroups: [ !GetAtt InternalLoadBalancerSecurityGroup.GroupId ]
Subnets: [ !Ref PrivateSubnet1, !Ref PrivateSubnet2, ]
Type: application
# Assign a dummy target group that with no real services as targets, so that we can create
# the listeners for the services.
DefaultInternalHTTPTargetGroup:
Type: AWS::ElasticLoadBalancingV2::TargetGroup
Condition: CreateInternalALB
Properties:
# Check if your application is healthy within 20 = 10*2 seconds, compared to 2.5 mins = 30*5 seconds.
HealthCheckIntervalSeconds: 10 # Default is 30.
HealthyThresholdCount: 2 # Default is 5.
HealthCheckTimeoutSeconds: 5
Port: 80
Protocol: HTTP
TargetGroupAttributes:
- Key: deregistration_delay.timeout_seconds
Value: 60 # Default is 300.
TargetType: ip
VpcId: !Ref VPC
InternalHTTPListener:
Metadata:
'aws:copilot:description': 'An internal load balancer listener to route HTTP traffic'
Type: AWS::ElasticLoadBalancingV2::Listener
Condition: CreateInternalALB
Properties:
DefaultActions:
- TargetGroupArn: !Ref DefaultInternalHTTPTargetGroup
Type: forward
LoadBalancerArn: !Ref InternalLoadBalancer
Port: 80
Protocol: HTTP
InternalHTTPSListener:
Metadata:
'aws:copilot:description': 'An internal load balancer listener to route HTTPS traffic'
Type: AWS::ElasticLoadBalancingV2::Listener
Condition: ExportInternalHTTPSListener
Properties:
DefaultActions:
- TargetGroupArn: !Ref DefaultInternalHTTPTargetGroup
Type: forward
LoadBalancerArn: !Ref InternalLoadBalancer
Port: 443
Protocol: HTTPS
InternalWorkloadsHostedZone:
Metadata:
'aws:copilot:description': 'A hosted zone named test.demo.internal for backends behind a private load balancer'
Condition: CreateInternalALB
Type: AWS::Route53::HostedZone
Properties:
Name: !Sub ${EnvironmentName}.${AppName}.internal
VPCs:
- VPCId: !Ref VPC
VPCRegion: !Ref AWS::Region
FileSystem:
Condition: CreateEFS
Type: AWS::EFS::FileSystem
Metadata:
'aws:copilot:description': 'An EFS filesystem for persistent task storage'
Properties:
BackupPolicy:
Status: ENABLED
Encrypted: true
FileSystemPolicy:
Version: '2012-10-17'
Id: CopilotEFSPolicy
Statement:
- Sid: AllowIAMFromTaggedRoles
Effect: Allow
Principal:
AWS: '*'
Action:
- elasticfilesystem:ClientWrite
- elasticfilesystem:ClientMount
Condition:
Bool:
'elasticfilesystem:AccessedViaMountTarget': true
StringEquals:
'iam:ResourceTag/copilot-application': !Sub '${AppName}'
'iam:ResourceTag/copilot-environment': !Sub '${EnvironmentName}'
- Sid: DenyUnencryptedAccess
Effect: Deny
Principal: '*'
Action: 'elasticfilesystem:*'
Condition:
Bool:
'aws:SecureTransport': false
LifecyclePolicies:
- TransitionToIA: AFTER_30_DAYS
PerformanceMode: generalPurpose
ThroughputMode: bursting
EFSSecurityGroup:
Metadata:
'aws:copilot:description': 'A security group to allow your containers to talk to EFS storage'
Type: AWS::EC2::SecurityGroup
Condition: CreateEFS
Properties:
GroupDescription: !Join ['', [!Ref AppName, '-', !Ref EnvironmentName, EFSSecurityGroup]]
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Sub 'copilot-${AppName}-${EnvironmentName}-efs'
EFSSecurityGroupIngressFromEnvironment:
Type: AWS::EC2::SecurityGroupIngress
Condition: CreateEFS
Properties:
Description: Ingress from containers in the Environment Security Group.
GroupId: !Ref EFSSecurityGroup
IpProtocol: -1
SourceSecurityGroupId: !Ref EnvironmentSecurityGroup
MountTarget1:
Type: AWS::EFS::MountTarget
Condition: CreateEFS
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref PrivateSubnet1
SecurityGroups:
- !Ref EFSSecurityGroup
MountTarget2:
Type: AWS::EFS::MountTarget
Condition: CreateEFS
Properties:
FileSystemId: !Ref FileSystem
SubnetId: !Ref PrivateSubnet2
SecurityGroups:
- !Ref EFSSecurityGroup
CustomResourceRole:
Metadata:
'aws:copilot:description': 'An IAM role to manage certificates and Route53 hosted zones'
Type: AWS::IAM::Role
Condition: DelegateDNS
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
-
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: /
Policies:
- PolicyName: "DNSandACMAccess"
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- "acm:ListCertificates"
- "acm:RequestCertificate"
- "acm:DescribeCertificate"
- "acm:GetCertificate"
- "acm:DeleteCertificate"
- "acm:AddTagsToCertificate"
- "sts:AssumeRole"
- "logs:*"
- "route53:ChangeResourceRecordSets"
- "route53:Get*"
- "route53:Describe*"
- "route53:ListResourceRecordSets"
- "route53:ListHostedZonesByName"
Resource:
- "*"
EnvironmentHostedZone:
Metadata:
'aws:copilot:description': "A Route 53 Hosted Zone for the environment's subdomain"
Type: "AWS::Route53::HostedZone"
Condition: DelegateDNS
Properties:
HostedZoneConfig:
Comment: !Sub "HostedZone for environment ${EnvironmentName} - ${EnvironmentName}.${AppName}.${AppDNSName}"
Name: !Sub ${EnvironmentName}.${AppName}.${AppDNSName}
CertificateValidationFunction:
Type: AWS::Lambda::Function
Condition: DelegateDNS
Properties:
Handler: "index.certificateRequestHandler"
Timeout: 900
MemorySize: 512
Role: !GetAtt 'CustomResourceRole.Arn'
Runtime: nodejs22.x
CustomDomainFunction:
Condition: ManagedAliases
Type: AWS::Lambda::Function
Properties:
Handler: "index.handler"
Timeout: 600
MemorySize: 512
Role: !GetAtt 'CustomResourceRole.Arn'
Runtime: nodejs22.x
DNSDelegationFunction:
Type: AWS::Lambda::Function
Condition: DelegateDNS
Properties:
Handler: "index.domainDelegationHandler"
Timeout: 600
MemorySize: 512
Role: !GetAtt 'CustomResourceRole.Arn'
Runtime: nodejs22.x
DelegateDNSAction:
Metadata:
'aws:copilot:description': 'Delegate DNS for environment subdomain'
Condition: DelegateDNS
Type: Custom::DNSDelegationFunction
DependsOn:
- DNSDelegationFunction
- EnvironmentHostedZone
Properties:
ServiceToken: !GetAtt DNSDelegationFunction.Arn
DomainName: !Sub ${AppName}.${AppDNSName}
SubdomainName: !Sub ${EnvironmentName}.${AppName}.${AppDNSName}
NameServers: !GetAtt EnvironmentHostedZone.NameServers
RootDNSRole: !Ref AppDNSDelegationRole
HTTPSCert:
Metadata:
'aws:copilot:description': 'Request and validate an ACM certificate for your domain'
Condition: DelegateDNS
Type: Custom::CertificateValidationFunction
DependsOn:
- CertificateValidationFunction
- EnvironmentHostedZone
- DelegateDNSAction
Properties:
ServiceToken: !GetAtt CertificateValidationFunction.Arn
AppName: !Ref AppName
EnvName: !Ref EnvironmentName
DomainName: !Ref AppDNSName