forked from aws-samples/amazon-sagemaker-secure-mlops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenv-main.yaml
1756 lines (1597 loc) · 66.2 KB
/
env-main.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
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
AWSTemplateFormatVersion: '2010-09-09'
Description: |
Create the Data Science environment
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Data Science Environment
Parameters:
- EnvName
- EnvType
- StartKernelGatewayApps
- EnvTypeStagingName
- EnvTypeProdName
- Label:
default: Deployment Options
Parameters:
- CreateEnvironmentIAMRoles
- CreateEnvironmentS3Buckets
- UseSharedServicesPyPiMirror
- Label:
default: Environment IAM Roles ARNs (only needed if created outside of this stack)
Parameters:
- DSTeamAdministratorRoleArn
- DataScientistRoleArn
- SageMakerExecutionRoleArn
- SageMakerPipelineExecutionRoleArn
- SageMakerModelExecutionRoleName
- SetupLambdaExecutionRoleArn
- SCProjectLaunchRoleArn
- StackSetAdministrationRoleArn
- StackSetExecutionRoleName
- Label:
default: S3 Buckets (only needed if created outside of this stack)
Parameters:
- DataBucketName
- ModelBucketName
- Label:
default: S3 Bucket Name with MLOps Seed Code
Parameters:
- SeedCodeS3BucketName
- Label:
default: Multi-account model deployment setup (provide OU ids or account lists)
Parameters:
- OrganizationalUnitStagingId
- OrganizationalUnitProdId
- StagingAccountList
- ProductionAccountList
- Label:
default: Infrastructure setup in the target accounts in staging and production OUs (multi-account only)
Parameters:
- SetupStackSetExecutionRoleName
- CreateTargetAccountNetworkInfra
- Label:
default: Availability Zone Configuration
Parameters:
- AvailabilityZones
- NumberOfAZs
- Label:
default: VPC Endpoint Creation
Parameters:
- CreateS3VPCEndpoint
- CreateSSMVPCEndpoint
- CreateCWVPCEndpoint
- CreateCWLVPCEndpoint
- CreateSageMakerAPIVPCEndpoint
- CreateSageMakerRuntimeVPCEndpoint
- CreateSageMakerNotebookVPCEndpoint
- CreateSTSVPCEndpoint
- CreateServiceCatalogVPCEndpoint
- CreateCodeCommitVPCEndpoint
- CreateCodeCommitAPIVPCEndpoint
- CreateCodePipelineVPCEndpoint
- CreateCodeBuildVPCEndpoint
- CreateECRAPIVPCEndpoint
- CreateECRVPCEndpoint
- CreateKMSVPCEndpoint
- Label:
default: Network Configuration
Parameters:
- CreateVPC
- CreateNATGateways
- ExistingVPCId
- ExistingS3VPCEndpointId
- VPCCIDR
- CreatePrivateSubnets
- PrivateSubnet1ACIDR
- PrivateSubnet2ACIDR
- PrivateSubnet3ACIDR
- PrivateSubnet4ACIDR
- PublicSubnet1CIDR
- PublicSubnet2CIDR
- PublicSubnet3CIDR
- PublicSubnet4CIDR
- Label:
default: VPC Flow Logs Configuration
Parameters:
- CreateVPCFlowLogsToCloudWatch
- CreateVPCFlowLogsRole
- VPCFlowLogsRoleArn
- VPCFlowLogsLogFormat
- VPCFlowLogsLogGroupRetention
- VPCFlowLogsMaxAggregationInterval
- VPCFlowLogsTrafficType
- VPCFlowLogsCloudWatchKMSKey
ParameterLabels:
EnvName:
default: Environment name
EnvType:
default: Environment stage name (dev, test, prod)
EnvTypeStagingName:
default: Environment name for staging environment
EnvTypeProdName:
default: Environment name for production environment
StartKernelGatewayApps:
default: Select YES to start the Data Science and Data Wrangler kernels on KernelGateway
DataBucketName:
default: Existing S3 bucket name to store ML data (only if created outside of this stack)
ModelBucketName:
default: Existing S3 bucket name to store ML models (only if created outside of this stack)
SeedCodeS3BucketName:
default: Existing S3 bucket name where MLOps seed code will be stored
CreateEnvironmentIAMRoles:
default: Create environment IAM roles
CreateEnvironmentS3Buckets:
default: Create environment S3 buckets
CreateS3VPCEndpoint:
default: Create S3 VPC endpoint
CreateSSMVPCEndpoint:
default: Create SSM VPC endpoint
CreateCWVPCEndpoint:
default: Create CloudWatch VPC endpoint
CreateCWLVPCEndpoint:
default: Create CloudWatch Logs VPC endpoint
CreateSageMakerAPIVPCEndpoint:
default: Create SageMaker API VPC endpoint
CreateSageMakerRuntimeVPCEndpoint:
default: Create SageMaker Runtime VPC endpoint
CreateSageMakerNotebookVPCEndpoint:
default: Create SageMaker Notebook VPC endpoint
CreateSTSVPCEndpoint:
default: Create STS VPC endpoint
CreateServiceCatalogVPCEndpoint:
default: Create Service Catalog endpoint
CreateCodeCommitVPCEndpoint:
default: Create CodeCommit VPC endpoint
CreateCodeCommitAPIVPCEndpoint:
default: Create CodeCommit API VPC endpoint
CreateCodePipelineVPCEndpoint:
default: Create CodePipeline VPC endpoint
CreateCodeBuildVPCEndpoint:
default: Create CodeBuild VPC endpoint
CreateECRAPIVPCEndpoint:
default: Create ECR API VPC endpoint
CreateECRVPCEndpoint:
default: Create ECR VPC endpoint
CreateKMSVPCEndpoint:
default: Create KMS VPC endpoint
UseSharedServicesPyPiMirror:
default: Use shared services PyPI mirror
DSTeamAdministratorRoleArn:
default: Data Science Team Administrator role ARN
DataScientistRoleArn:
default: Data Scientist role ARN
SageMakerExecutionRoleArn:
default: SageMaker and SageMaker Notebook execution role ARN
SageMakerPipelineExecutionRoleArn:
default: SageMaker pipeline execution role ARN
SageMakerModelExecutionRoleName:
default: SageMaker model endpoint execution role name
StackSetAdministrationRoleArn:
default: CloudFormation StackSet administration role ARN
StackSetExecutionRoleName:
default: CloudFormation StackSet execution role name
SetupLambdaExecutionRoleArn:
default: Execution role ARN for Lambda function for setup script
SCProjectLaunchRoleArn:
default: Service Catalog Project Launch role ARN
OrganizationalUnitStagingId:
default: OU Id for the organizational unit with data science staging account. Leave empty for single-account deployment
OrganizationalUnitProdId:
default: OU Id for the organizational unit with data science production account. Leave empty for single-account deployment
StagingAccountList:
default: Comma-delimited list of the staging accounts for multi-account model deployment. Leave empty for single-account deployment
ProductionAccountList:
default: Comma-delimited list of the production accounts for multi-account model deployment. Leave empty for single-account deployment
SetupStackSetExecutionRoleName:
default: Stack set execution role name for initial infrastructure setup in the target accounts in the staging and production OUs
CreateTargetAccountNetworkInfra:
default: Create a private VPC and VPC endpoints for model hosting in the target accounts in the staging and production OUs
AvailabilityZones:
default: Availability Zones
NumberOfAZs:
default: Number of Availability Zones
CreateVPC:
default: Create a new VPC
CreateNATGateways:
default: Create NAT Gateways (per AZ)
ExistingVPCId:
default: Existing VPC Id
ExistingS3VPCEndpointId:
default: Existing S3 VPC endpoint Id
VPCCIDR:
default: CICD block for a new or existing VPC
CreatePrivateSubnets:
default: Create private subnets
PrivateSubnet1ACIDR:
default: Private subnet 1 CIDR
PrivateSubnet2ACIDR:
default: Private subnet 2 CIDR
PrivateSubnet3ACIDR:
default: Private subnet 3 CIDR
PrivateSubnet4ACIDR:
default: Private subnet 4 CIDR
PublicSubnet1CIDR:
default: Public subnet 1 CIDR
PublicSubnet2CIDR:
default: Public subnet 2 CIDR
PublicSubnet3CIDR:
default: Public subnet 3 CIDR
PublicSubnet4CIDR:
default: Public subnet 4 CIDR
CreateVPCFlowLogsToCloudWatch:
default: Create VPC Flow Logs (CloudWatch)
CreateVPCFlowLogsRole:
default: Create VPC Flow Logs execution role
VPCFlowLogsRoleArn:
default: VPC Flow Logs Role ARN
VPCFlowLogsLogFormat:
default: VPC Flow Logs - Log Format
VPCFlowLogsLogGroupRetention:
default: VPC Flow Logs - Log Group Retention
VPCFlowLogsMaxAggregationInterval:
default: VPC Flow Logs - Max Aggregation Interval
VPCFlowLogsTrafficType:
default: VPC Flow Logs - Traffic Type
VPCFlowLogsCloudWatchKMSKey:
default: CloudWatch Logs KMS Key for VPC flow logs
Outputs:
AssumeTeamAdminRole:
Description: URL for assuming the role of a environment admin
Value: !If
- IAMRolesCondition
- !GetAtt EnvironmentIAMRoles.Outputs.AssumeTeamAdminRole
- !Sub
- 'https://signin.aws.amazon.com/switchrole?account=${AWS::AccountId}&roleName=${DSTeamAdministratorRoleName}&displayName=${DSTeamAdministratorRoleName}'
- DSTeamAdministratorRoleName: !Select ['1', !Split [ '/', !Select ['5', !Split [':', !Ref DSTeamAdministratorRoleArn ]]]]
AssumeDataScientistRole:
Description: URL for assuming the role of a environment user
Value: !If
- IAMRolesCondition
- !GetAtt EnvironmentIAMRoles.Outputs.AssumeDataScientistRole
- !Sub
- 'https://signin.aws.amazon.com/switchrole?account=${AWS::AccountId}&roleName=${DataScientistRoleName}&displayName=${DataScientistRoleName}'
- DataScientistRoleName: !Select ['1', !Split [ '/', !Select ['5', !Split [':', !Ref DataScientistRoleArn ]]]]
SageMakerDomainId:
Description: SageMaker Domain Id
Value: !GetAtt EnvironmentSageMakerStudio.Outputs.SageMakerDomainId
GetOUAccountsLambdaArn:
Description: Lambda function to retrieve the accounts id from the parent OUs
Value: !GetAtt GetOUAccountsLambda.Arn
Export:
Name: 'ds-ou-accounts-lambda-arn'
Parameters:
EnvName:
Type: String
AllowedPattern: '[a-z0-9\-]*'
Description: Please specify your data science environment name. Used as a suffix for environment resource names.
Default: 'sm-mlops'
EnvType:
Description: System Environment (e.g. dev, test, prod). Used as a suffix for environment resource names.
Type: String
Default: 'dev'
EnvTypeStagingName:
Description: Environment name for staging environment
Type: String
Default: 'staging'
EnvTypeProdName:
Description: Environment name for production environment
Type: String
Default: 'prod'
StartKernelGatewayApps:
Type: String
Description: Start the KernelGateway Apps (Data Science and Data Wrangler)
AllowedValues:
- 'YES'
- 'NO'
Default: 'NO'
DataBucketName:
Description: S3 bucket name to store data (only if created outside of this stack)
Type: String
Default: ''
ModelBucketName:
Description: S3 bucket name to store models (only if created outside of this stack)
Type: String
Default: ''
SeedCodeS3BucketName:
Description: S3 bucket name to store MLOps seed code (the S3 bucket must exist)
Type: String
CreateEnvironmentIAMRoles:
Description: If YES, all IAM Roles for Data Science environment will be automatically provisioned. If NO, you have to provide the IAM roles
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateEnvironmentS3Buckets:
Description: Select YES if you want to create Amazon S3 buckets for models and data
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateS3VPCEndpoint:
Description: Set to NO to disable creation of an S3 VPC endpoint (and use an existing one)
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateSSMVPCEndpoint:
Description: Set to NO to disable creation of an SSM VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCWVPCEndpoint:
Description: Set to NO to disable creation of a CloudWatch VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCWLVPCEndpoint:
Description: Set to NO to disable creation of a CloudWatch logs VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateSageMakerAPIVPCEndpoint:
Description: Set to NO to disable creation of a SageMaker API VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateSageMakerRuntimeVPCEndpoint:
Description: Set to NO to disable creation of a SageMaker Runtime VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateSageMakerNotebookVPCEndpoint:
Description: Set to NO to disable creation of a SageMaker Notebook VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateSTSVPCEndpoint:
Description: Set to NO to disable creation of an STS VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateServiceCatalogVPCEndpoint:
Description: Set to NO to disable creation of an Service Catalog VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCodeCommitVPCEndpoint:
Description: Set to NO to disable creation of a CodeCommit VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCodeCommitAPIVPCEndpoint:
Description: Set to NO to disable creation of a CodeCommit API VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCodePipelineVPCEndpoint:
Description: Set to NO to disable creation of a CodePipeline VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateCodeBuildVPCEndpoint:
Description: Set to NO to disable creation of a CodeBuild VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateECRAPIVPCEndpoint:
Description: Set to NO to disable creation of an ECR API VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateECRVPCEndpoint:
Description: Set to NO to disable creation of a ECR VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateKMSVPCEndpoint:
Description: Set to NO to disable creation of a KMS VPC endpoint
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
UseSharedServicesPyPiMirror:
Description: Select YES if you want to use shared services PyPI mirror (must be created in the core stack)
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'NO'
DSTeamAdministratorRoleArn:
Description: The ARN of the DataScienceTeamAdministrator role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
DataScientistRoleArn:
Description: The ARN of the DataScientist role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
SageMakerExecutionRoleArn:
Description: The ARN of the SageMaker Execution role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
SageMakerPipelineExecutionRoleArn:
Description: The ARN of the SageMaker Pipeline Execution role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
SageMakerModelExecutionRoleName:
Description: The name of the SageMaker model endpoint execution role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
StackSetAdministrationRoleArn:
Description: The ARN of the CloudFormation StackSet administration role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
StackSetExecutionRoleName:
Description: The name of the CloudFormation StackSet execution role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
SetupLambdaExecutionRoleArn:
Description: The ARN of the execution role for the Lambda function for SageMaker Studio setup
Type: String
Default: ''
SCProjectLaunchRoleArn:
Description: The ARN of the Service Catalog Project launch role role if created outside the stack. Must be provided if Create IAM Roles = NO
Type: String
Default: ''
OrganizationalUnitStagingId:
Type: String
Description: OU Id of the organizational unit that holds the data science staging account
Default: ''
OrganizationalUnitProdId:
Type: String
Description: OU Id of the organizational unit that holds the data science production account
Default: ''
StagingAccountList:
Type: String
Description: Comma-delimited list of staging account ids for multi-account model deployment
Default: ''
ProductionAccountList:
Type: String
Description: Comma-delimited list of production account ids for multi-account model deployment
Default: ''
SetupStackSetExecutionRoleName:
Type: String
Description: Stack set execution role name for initial infrastructure setup in the target accounts (staging and production OUs).
Default: ''
CreateTargetAccountNetworkInfra:
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
Description: Set to NO when you do not want to create any network infra hosting in the target account. Model hosting VPC and VPC endpoints are required for multi-account model deployment.
Type: String
AvailabilityZones:
Description: 'List of Availability Zones to use for the subnets in the VPC. Note: The logical order is preserved.'
Type: List<AWS::EC2::AvailabilityZone::Name>
NumberOfAZs:
AllowedValues:
- '1'
- '2'
- '3'
- '4'
Default: '2'
Description: Number of Availability Zones to use in the VPC. This must match your selections in the list of Availability Zones parameter.
Type: String
CreateVPC:
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
Description: Set to NO when you want to re-use an existing VPC. If NO, the Existing VPC Id must be provided
Type: String
CreateNATGateways:
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
Description: Set to NO when creating only private subnets. If YES, public subnets for each AZ will be created as well as an Internet Gateway
Type: String
ExistingVPCId:
Description: Enter an existing VPC Id for deployment or leave empty if "Create a new VPC" is set to YES
Default: ''
Type: String
ExistingS3VPCEndpointId:
Description: Id of the existing S3 VPC endpoint (must be provided if CreateS3VPCEndpoint = NO)
Type: String
Default: ''
VPCCIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/16
Description: CIDR block for the new VPC
Type: String
CreatePrivateSubnets:
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
Description: Set to NO when you want to re-use existing subnets in the existing VPC (VPC Id must be provided)
Type: String
PrivateSubnet1ACIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.0.0/19
Description: CIDR block for private subnet 1A located in Availability Zone 1
Type: String
PrivateSubnet2ACIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.32.0/19
Description: CIDR block for private subnet 2A located in Availability Zone 2
Type: String
PrivateSubnet3ACIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.64.0/19
Description: CIDR block for private subnet 3A located in Availability Zone 3
Type: String
PrivateSubnet4ACIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.96.0/19
Description: CIDR block for private subnet 4A located in Availability Zone 4
Type: String
PublicSubnet1CIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.128.0/20
Description: CIDR block for the public DMZ subnet 1 located in Availability Zone 1
Type: String
PublicSubnet2CIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.144.0/20
Description: CIDR block for the public DMZ subnet 2 located in Availability Zone 2
Type: String
PublicSubnet3CIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.160.0/20
Description: CIDR block for the public DMZ subnet 3 located in Availability Zone 3
Type: String
PublicSubnet4CIDR:
AllowedPattern: ^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(1[6-9]|2[0-8]))$
ConstraintDescription: CIDR block parameter must be in the form x.x.x.x/16-28
Default: 10.0.176.0/20
Description: CIDR block for the public DMZ subnet 4 located in Availability Zone 4
Type: String
CreateVPCFlowLogsToCloudWatch:
Description: Select YES if you want to create an IAM Role for VPC Flow Logs to write the logs into a CloudWatch log group
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
CreateVPCFlowLogsRole:
Description: Select YES if you want to create a VPC Flow Logs execution role
Type: String
AllowedValues:
- 'YES'
- 'NO'
Default: 'YES'
VPCFlowLogsRoleArn:
Default: ''
Description: VPC Flow Logs role ARN used to deliver the logs into CloudWatch log group.
Type: String
VPCFlowLogsLogFormat:
AllowedPattern: '^(\$\{[a-z-]+\})$|^((\$\{[a-z-]+\} )*\$\{[a-z-]+\})$'
Default:
'${version} ${account-id} ${interface-id} ${srcaddr} ${dstaddr} ${srcport} ${dstport} ${protocol} ${packets} ${bytes} ${start} ${end} ${action}
${log-status}'
Description:
The fields to include in the flow log record, in the order in which they should appear. Specify the fields using the ${field-id} format,
separated by spaces. Using the Default Format as the default value.
Type: String
VPCFlowLogsLogGroupRetention:
AllowedValues: [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
Default: 14
Description: Number of days to retain the VPC Flow Logs in CloudWatch
Type: String
VPCFlowLogsMaxAggregationInterval:
AllowedValues:
- 60
- 600
Default: 600
Description:
The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. You can specify 60 seconds (1
minute) or 600 seconds (10 minutes).
Type: String
VPCFlowLogsTrafficType:
AllowedValues:
- ACCEPT
- ALL
- REJECT
Default: REJECT
Description: The type of traffic to log. You can log traffic that the resource accepts or rejects, or all traffic.
Type: String
VPCFlowLogsCloudWatchKMSKey:
AllowedPattern: '^$|^arn:(aws[a-zA-Z-]*)?:kms:[a-z0-9-]+:\d{12}:key\/[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$'
ConstraintDescription: 'Key ARN example: arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab'
Default: ''
Description:
(Optional) KMS Key ARN to use for encrypting the VPC flow logs data. If empty, encryption is enabled with CloudWatch Logs managing the
server-side encryption keys.
Type: String
Conditions:
IAMRolesCondition: !Equals [ !Ref CreateEnvironmentIAMRoles, 'YES' ]
VPCFlowLogsRoleCondition: !Equals [ !Ref CreateVPCFlowLogsRole, 'YES' ]
ExistingVPCCondition: !Equals [!Ref 'CreateVPC', 'NO']
ExistingPrivateSubnetsCondition: !And
- !Condition ExistingVPCCondition
- !Equals [!Ref CreatePrivateSubnets, 'NO']
IAMRoles&VPCFlowLogsRoleCondition: !And [ !Condition IAMRolesCondition, !Condition VPCFlowLogsRoleCondition]
S3BucketsConditions: !Equals [ !Ref CreateEnvironmentS3Buckets, 'YES' ]
SharedServicesPyPiMirrorCondition: !Equals [ !Ref UseSharedServicesPyPiMirror, 'YES' ]
OrganizationalUnitCondition: !And
- !Not [ !Equals [ !Ref OrganizationalUnitStagingId, ''] ]
- !Not [ !Equals [ !Ref OrganizationalUnitProdId, ''] ]
AccountListCondition: !And
- !Not [ !Equals [ !Ref StagingAccountList, ''] ]
- !Not [ !Equals [ !Ref ProductionAccountList, ''] ]
MultiAccountDeploymentCondition: !Or
- !Condition OrganizationalUnitCondition
- !Condition AccountListCondition
IAMRolesStackSetDeploymentCondition: !And
- !Condition MultiAccountDeploymentCondition
- !Condition IAMRolesCondition
TargetAccountNetworkInfraCondition: !Equals [ !Ref CreateTargetAccountNetworkInfra, 'YES' ]
NetworkInfraStackSetDeploymentCondition: !And
- !Condition MultiAccountDeploymentCondition
- !Condition TargetAccountNetworkInfraCondition
Rules:
IAMRoles:
RuleCondition: !Equals [ !Ref CreateEnvironmentIAMRoles, 'NO' ]
Assertions:
- Assert: !And
- !Not [ !Equals [ !Ref DSTeamAdministratorRoleArn, '' ] ]
- !Not [ !Equals [ !Ref DataScientistRoleArn, '' ] ]
- !Not [ !Equals [ !Ref SageMakerExecutionRoleArn, '' ] ]
- !Not [ !Equals [ !Ref SageMakerPipelineExecutionRoleArn, '' ] ]
- !Not [ !Equals [ !Ref SageMakerModelExecutionRoleName, '' ] ]
- !Not [ !Equals [ !Ref StackSetAdministrationRoleArn, '' ] ]
- !Not [ !Equals [ !Ref StackSetExecutionRoleName, '' ] ]
- !Not [ !Equals [ !Ref SCProjectLaunchRoleArn, '' ] ]
- !Not [ !Equals [ !Ref SetupLambdaExecutionRoleArn, '' ] ]
AssertDescription: ARNs and role names must be provided for all IAM roles if Create environemtn IAM Roles = NO
VPCFlowLogsRole:
RuleCondition: !Equals [ !Ref CreateEnvironmentIAMRoles, 'NO' ]
Assertions:
- Assert: !Equals [ !Ref CreateVPCFlowLogsRole, 'NO' ]
AssertDescription: Create VPC Flow Logs execution role cannot be set to YES if Create environemtn IAM Roles is set NO
OrganizationalUnitIds:
RuleCondition: !Or
- !Not [ !Equals [ !Ref OrganizationalUnitStagingId, '' ] ]
- !Not [ !Equals [ !Ref OrganizationalUnitProdId, '' ] ]
Assertions:
- Assert: !And
- !Not [ !Equals [ !Ref OrganizationalUnitProdId, '' ] ]
- !Not [ !Equals [ !Ref OrganizationalUnitStagingId, '' ] ]
- !Equals [ !Ref StagingAccountList, '']
- !Equals [ !Ref ProductionAccountList, '']
AssertDescription: Both staging and production OU ids must be provided if one OU id is provided and both StagingAccountList and ProductionAccountList must be empty
AccountList:
RuleCondition: !Or
- !Not [ !Equals [ !Ref StagingAccountList, '' ] ]
- !Not [ !Equals [ !Ref ProductionAccountList, '' ] ]
Assertions:
- Assert: !And
- !Equals [ !Ref OrganizationalUnitProdId, '' ]
- !Equals [ !Ref OrganizationalUnitStagingId, '' ]
- !Not [ !Equals [ !Ref StagingAccountList, ''] ]
- !Not [ !Equals [ !Ref ProductionAccountList, ''] ]
AssertDescription: Both StagingAccountList and ProductionAccountList must be provided if one list is provided and both OrganizationalUnitProdId and OrganizationalUnitProdId must be empty
SetupStackSetExecutionRole:
RuleCondition: !And
- !Not [ !Equals [ !Ref OrganizationalUnitStagingId, ''] ]
- !Not [ !Equals [ !Ref OrganizationalUnitProdId, ''] ]
- !Or
- !Equals [ !Ref CreateEnvironmentIAMRoles, 'YES' ]
- !Equals [ !Ref CreateTargetAccountNetworkInfra, 'YES' ]
Assertions:
- Assert: !Not [ !Equals [ !Ref SetupStackSetExecutionRoleName, '' ] ]
AssertDescription: SetupStackSetExecutionRoleName must be provided for multi-account model deployment option
Resources:
# Environement IAM roles for personas and services
EnvironmentIAMRoles:
Type: AWS::CloudFormation::Stack
Condition: IAMRolesCondition
Properties:
Parameters:
EnvName: !Ref EnvName
EnvType: !Ref EnvType
CreateVPCFlowLogsRole: !Ref CreateVPCFlowLogsRole
SetupStackSetExecutionRoleName: !If
- IAMRolesStackSetDeploymentCondition
- !Ref SetupStackSetExecutionRoleName
- !Ref AWS::NoValue
TemplateURL: env-iam.yaml
Tags:
- Key: EnvironmentName
Value: !Ref EnvName
- Key: EnvironmentType
Value: !Ref EnvType
# This stack deployes the IAM Roles which will be provisioned in the target accounts (staging and production) into the current account
# These roles are needed for StackSet operations and model deployment
# This stack deploys these roles to _the current account_ to enable a trivial single-account model deployment
# Single-account model deployment is still uses StackSet operations and a separate model execution role
EnvironmentTargetAccountRoles:
Type: AWS::CloudFormation::Stack
Condition: IAMRolesCondition
Properties:
Parameters:
EnvName: !Ref EnvName
EnvType: !Ref EnvType
PipelineExecutionRoleArn: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:role/service-role/AmazonSageMakerServiceCatalogProductsUseRole'
AdministratorAccountId: !Ref AWS::AccountId
ModelS3KMSKeyArn: !GetAtt EnvironmentKMSKeys.Outputs.S3BucketKMSKeyArn
ModelBucketName: !GetAtt EnvironmentVPC.Outputs.ModelBucketName
TemplateURL: env-iam-target-account-roles.yaml
Tags:
- Key: EnvironmentName
Value: !Ref EnvName
- Key: EnvironmentType
Value: !Ref EnvType
# These two stack set deploys the IAM roles in the target accounts - staging and production - defined by the provided OU Ids or account lists
# Using 'SELF_MANAGED' permission model for this deployment
# Deploy IAM roles into the target accounts (staging and production)
EnvironmentTargetAccountRolesStackSet:
Type: AWS::CloudFormation::StackSet
Condition: IAMRolesStackSetDeploymentCondition
Properties:
AdministrationRoleARN: !GetAtt EnvironmentIAMRoles.Outputs.StackSetAdministrationRoleArn
Capabilities:
- CAPABILITY_NAMED_IAM
Description: Deploys stack set execution and model execution roles to the target accounts
ExecutionRoleName: !Ref SetupStackSetExecutionRoleName
OperationPreferences:
MaxConcurrentPercentage: 100
Parameters:
-
ParameterKey: 'EnvName'
ParameterValue: !Ref EnvName
-
ParameterKey: 'SageMakerModelExecutionRoleName'
ParameterValue: !GetAtt EnvironmentTargetAccountRoles.Outputs.SageMakerModelExecutionRoleName
-
ParameterKey: 'StackSetExecutionRoleName'
ParameterValue: !GetAtt EnvironmentTargetAccountRoles.Outputs.StackSetExecutionRoleName
-
ParameterKey: 'PipelineExecutionRoleArn'
ParameterValue: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:role/service-role/AmazonSageMakerServiceCatalogProductsUseRole'
-
ParameterKey: 'AdministratorAccountId'
ParameterValue: !Ref AWS::AccountId
-
ParameterKey: 'ModelS3KMSKeyArn'
ParameterValue: !GetAtt EnvironmentKMSKeys.Outputs.S3BucketKMSKeyArn
-
ParameterKey: "ModelBucketName"
ParameterValue: !GetAtt EnvironmentVPC.Outputs.ModelBucketName
PermissionModel: 'SELF_MANAGED'
StackInstancesGroup:
-
Regions:
- !Ref AWS::Region
DeploymentTargets:
Accounts: !If
- OrganizationalUnitCondition
- !GetAtt GetOUAccountsStaging.Accounts
- !Split [',', !Ref StagingAccountList]
ParameterOverrides:
-
ParameterKey: 'EnvType'
ParameterValue: !Ref EnvTypeStagingName
-
Regions:
- !Ref AWS::Region
DeploymentTargets:
Accounts: !If
- OrganizationalUnitCondition
- !GetAtt GetOUAccountsProd.Accounts
- !Split [',', !Ref ProductionAccountList]
ParameterOverrides:
-
ParameterKey: 'EnvType'
ParameterValue: !Ref EnvTypeProdName
StackSetName: !Sub '${EnvName}-${AWS::Region}-target-account-roles'
TemplateURL: 'https://s3.amazonaws.com/< S3_CFN_STAGING_BUCKET_PATH >/env-iam-target-account-roles.yaml'
Tags:
- Key: EnvironmentName
Value: !Ref EnvName
- Key: EnvironmentType
Value: !Ref EnvType
# Environment VPC and network resources
EnvironmentVPC:
Type: AWS::CloudFormation::Stack
Properties:
Parameters:
EnvName: !Ref EnvName
EnvType: !Ref EnvType
AvailabilityZones: !Join [ ',', !Ref AvailabilityZones ]
NumberOfAZs: !Ref NumberOfAZs
CreateVPC: !Ref CreateVPC
CreateNATGateways: !Ref CreateNATGateways
ExistingVPCId: !Ref ExistingVPCId
VPCCIDR: !Ref VPCCIDR
CreatePrivateSubnets: !Ref CreatePrivateSubnets
ExistingPrivateSubnetIds: !If
- ExistingPrivateSubnetsCondition
- !Join [',', !GetAtt GetNetworkConfiguration.SubnetIds]
- !Ref AWS::NoValue
PrivateSubnet1ACIDR: !Ref PrivateSubnet1ACIDR
PrivateSubnet2ACIDR: !Ref PrivateSubnet2ACIDR
PrivateSubnet3ACIDR: !Ref PrivateSubnet3ACIDR
PrivateSubnet4ACIDR: !Ref PrivateSubnet4ACIDR
PublicSubnet1CIDR: !Ref PublicSubnet1CIDR
PublicSubnet2CIDR: !Ref PublicSubnet2CIDR
PublicSubnet3CIDR: !Ref PublicSubnet3CIDR
PublicSubnet4CIDR: !Ref PublicSubnet4CIDR
CreateVPCFlowLogsToCloudWatch: !Ref CreateVPCFlowLogsToCloudWatch
VPCFlowLogsRoleArn: !If
- IAMRoles&VPCFlowLogsRoleCondition
- !GetAtt EnvironmentIAMRoles.Outputs.VPCFlowLogsRoleArn
- !Ref VPCFlowLogsRoleArn
VPCFlowLogsCloudWatchKMSKey: !Ref VPCFlowLogsCloudWatchKMSKey
VPCFlowLogsLogFormat: !Ref VPCFlowLogsLogFormat
VPCFlowLogsLogGroupRetention: !Ref VPCFlowLogsLogGroupRetention
VPCFlowLogsMaxAggregationInterval: !Ref VPCFlowLogsMaxAggregationInterval
VPCFlowLogsTrafficType: !Ref VPCFlowLogsTrafficType
# VPC endpoints parameters
CreateS3VPCEndpoint: !Ref CreateS3VPCEndpoint
CreateSSMVPCEndpoint: !Ref CreateSSMVPCEndpoint
CreateCWVPCEndpoint: !Ref CreateCWVPCEndpoint
CreateCWLVPCEndpoint: !Ref CreateCWLVPCEndpoint
CreateSageMakerAPIVPCEndpoint: !Ref CreateSageMakerAPIVPCEndpoint
CreateSageMakerRuntimeVPCEndpoint: !Ref CreateSageMakerRuntimeVPCEndpoint
CreateSageMakerNotebookVPCEndpoint: !Ref CreateSageMakerNotebookVPCEndpoint
CreateSTSVPCEndpoint: !Ref CreateSTSVPCEndpoint
CreateServiceCatalogVPCEndpoint: !Ref CreateServiceCatalogVPCEndpoint
CreateCodeCommitVPCEndpoint: !Ref CreateCodeCommitVPCEndpoint
CreateCodeCommitAPIVPCEndpoint: !Ref CreateCodeCommitAPIVPCEndpoint
CreateCodePipelineVPCEndpoint: !Ref CreateCodePipelineVPCEndpoint
CreateCodeBuildVPCEndpoint: !Ref CreateCodeBuildVPCEndpoint
CreateECRAPIVPCEndpoint: !Ref CreateECRAPIVPCEndpoint
CreateECRVPCEndpoint: !Ref CreateECRVPCEndpoint
CreateKMSVPCEndpoint: !Ref CreateKMSVPCEndpoint
ExistingS3VPCEndpointId: !Ref ExistingS3VPCEndpointId
ExistingPrivateRouteTableIds: !If
- ExistingPrivateSubnetsCondition
- !Join [',', !GetAtt GetNetworkConfiguration.RouteTableIds]
- !Ref AWS::NoValue
PyPIMirrorEndpointServiceName: !If
- SharedServicesPyPiMirrorCondition
- !ImportValue 'ds-pypimirror-shared-service-endpoint-name'
- !Ref AWS::NoValue
DataBucketName: !If
- S3BucketsConditions
- !Sub '${EnvName}-${EnvType}-${AWS::Region}-data'
- !Ref DataBucketName
ModelBucketName: !If
- S3BucketsConditions
- !Sub '${EnvName}-${EnvType}-${AWS::Region}-models'
- !Ref ModelBucketName
TemplateURL: env-vpc.yaml
Tags: