-
Notifications
You must be signed in to change notification settings - Fork 1
/
idp-deploy.yaml
309 lines (294 loc) · 10.5 KB
/
idp-deploy.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
AWSTemplateFormatVersion: "2010-09-09"
Description: |
(SO9052) - This solution creates an Amazon SageMaker Studio domain along with the necessary resources required for the Intelligent Document Processing Workshop.
Parameters:
UserProfileName:
Type: String
Description: The user profile name for the IDP workshop
Default: 'SageMakerUser'
DomainName:
Type: String
Description: The domain name of the Sagemaker studio instance
Default: 'IDPSagemakerDomain'
Mappings:
RegionMap:
us-east-1:
datascience: "arn:aws:sagemaker:us-east-1:081325390199:image/datascience-1.0"
us-east-2:
datascience: "arn:aws:sagemaker:us-east-2:429704687514:image/datascience-1.0"
us-west-1:
datascience: "arn:aws:sagemaker:us-west-1:742091327244:image/datascience-1.0"
us-west-2:
datascience: "arn:aws:sagemaker:us-west-2:236514542706:image/datascience-1.0"
af-south-1:
datascience: "arn:aws:sagemaker:af-south-1:559312083959:image/datascience-1.0"
ap-east-1:
datascience: "arn:aws:sagemaker:ap-east-1:493642496378:image/datascience-1.0"
ap-south-1:
datascience: "arn:aws:sagemaker:ap-south-1:394103062818:image/datascience-1.0"
ap-northeast-2:
datascience: "arn:aws:sagemaker:ap-northeast-2:806072073708:image/datascience-1.0"
ap-southeast-1:
datascience: "arn:aws:sagemaker:ap-southeast-1:492261229750:image/datascience-1.0"
ap-southeast-2:
datascience: "arn:aws:sagemaker:ap-southeast-2:452832661640:image/datascience-1.0"
ap-northeast-1:
datascience: "arn:aws:sagemaker:ap-northeast-1:102112518831:image/datascience-1.0"
ca-central-1:
datascience: "arn:aws:sagemaker:ca-central-1:310906938811:image/datascience-1.0"
eu-central-1:
datascience: "arn:aws:sagemaker:eu-central-1:936697816551:image/datascience-1.0"
eu-west-1:
datascience: "arn:aws:sagemaker:eu-west-1:470317259841:image/datascience-1.0"
eu-west-2:
datascience: "arn:aws:sagemaker:eu-west-2:712779665605:image/datascience-1.0"
eu-west-3:
datascience: "arn:aws:sagemaker:eu-west-3:615547856133:image/datascience-1.0"
eu-north-1:
datascience: "arn:aws:sagemaker:eu-north-1:243637512696:image/datascience-1.0"
eu-south-1:
datascience: "arn:aws:sagemaker:eu-south-1:488287956546:image/sagemaker-data-wrangler-1.0"
sa-east-1:
datascience: "arn:aws:sagemaker:sa-east-1:782484402741:image/datascience-1.0"
Resources:
LambdaExecutionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- "sts:AssumeRole"
Path: /
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess'
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
SageMakerExecutionRole:
Type: AWS::IAM::Role
Properties:
Description: 'Test role for sagemaker'
Policies:
- PolicyName: s3-access
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action:
- s3:GetObject
- s3:PutObject
- s3:DeleteObject
- s3:ListBucket
Resource: arn:aws:s3:::*
- PolicyName: comprehend-passrole
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action:
- iam:PassRole
Resource: arn:aws:iam::*:role/*
Condition:
StringLikeIfExists:
'iam:PassedToService': "comprehend.amazonaws.com"
- PolicyName: textract-comprehend-sl-access
PolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Action:
- textract:GetDocumentTextDetection
- textract:GetDocumentAnalysis
- textract:AnalyzeDocument
- textract:AnalyzeID
- textract:AnalyzeExpense
- textract:DetectDocumentText
- textract:StartDocumentAnalysis
- textract:StartDocumentTextDetection
- comprehend:DetectEntities
- comprehend:DetectPiiEntities
- comprehend:ContainsPiiEntities
- comprehend:DescribePiiEntitiesDetectionJob
- comprehend:ListPiiEntitiesDetectionJobs
- comprehend:StartPiiEntitiesDetectionJob
- comprehend:StopPiiEntitiesDetectionJob
- comprehend:StartEntitiesDetectionJob
- comprehend:ClassifyDocument
- comprehend:DescribeDocumentClassificationJob
- comprehend:DescribeDocumentClassifier
- comprehend:CreateDocumentClassifier
- comprehend:CreateEntityRecognizer
- comprehend:DescribeEntityRecognizer
- comprehend:CreateEndpoint
- comprehend:DescribeEndpoint
- comprehend:DeleteEndpoint
- comprehend:DeleteDocumentClassifier
- comprehend:DeleteEntityRecognizer
- comprehend:StopTrainingDocumentClassifier
- comprehend:StopTrainingEntityRecognizer
- comprehend:ListEndpoints
- comprehend:ListEntityRecognizers
- comprehend:ListEntityRecognizerSummaries
- comprehend:ListDocumentClassifiers
- comprehend:ListDocumentClassifierSummaries
- comprehend:ImportModel
- comprehendmedical:DetectEntitiesV2
- comprehendmedical:DetectPHI
- comprehendmedical:InferICD10CM
- comprehendmedical:InferRxNorm
- comprehendmedical:InferSNOMEDCT
- comprehendmedical:StartICD10CMInferenceJob
- comprehendmedical:StartRxNormInferenceJob
- comprehendmedical:StartSNOMEDCTInferenceJob
- comprehendmedical:StartPHIDetectionJob
Resource: '*'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
-
Effect: Allow
Principal:
Service:
- sagemaker.amazonaws.com
- comprehend.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonSageMakerFullAccess
- arn:aws:iam::aws:policy/IAMReadOnlyAccess
- arn:aws:iam::aws:policy/AmazonAugmentedAIIntegratedAPIAccess
# Adding a wait time after SageMakerExecutionRole creation
DomainDeploymentDelay:
Type: 'Custom::Delay'
DependsOn: SageMakerExecutionRole
Properties:
ServiceToken: !GetAtt DelayLambda.Arn
TimeToWait: 180
DelayLambda:
Type: 'AWS::Lambda::Function'
Properties:
Handler: "index.handler"
Timeout: 660
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: python3.7
Code:
ZipFile: |
import json
import cfnresponse
import time
def handler(event, context):
time_to_wait = int(event['ResourceProperties']['TimeToWait'])
print(f'Waiting for {time_to_wait} seconds')
time.sleep(time_to_wait)
print(f'Waiting finished')
cfnresponse.send(event, context, cfnresponse.SUCCESS, {},'')
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
PublicSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.0.0/20
VpcId: !Ref VPC
PrivateSubnet:
Type: AWS::EC2::Subnet
Properties:
CidrBlock: 10.0.32.0/20
VpcId: !Ref VPC
StudioDomain:
Type: AWS::SageMaker::Domain
DependsOn: DomainDeploymentDelay
Properties:
AppNetworkAccessType: PublicInternetOnly
AuthMode: IAM
DefaultUserSettings:
ExecutionRole: !GetAtt SageMakerExecutionRole.Arn
DomainName: !Ref DomainName
SubnetIds: [!Ref PrivateSubnet, !Ref PublicSubnet]
VpcId: !Ref VPC
UserProfile:
Type: AWS::SageMaker::UserProfile
Properties:
DomainId: !GetAtt StudioDomain.DomainId
UserProfileName: !Ref UserProfileName
UserSettings:
ExecutionRole: !GetAtt SageMakerExecutionRole.Arn
JupyterApp:
Type: AWS::SageMaker::App
DependsOn: UserProfile
Properties:
AppName: default
AppType: JupyterServer
DomainId: !GetAtt StudioDomain.DomainId
UserProfileName: !Ref UserProfileName
DataScienceApp:
Type: AWS::SageMaker::App
DependsOn: UserProfile
Properties:
AppName: instance-event-engine-datascience-ml-t3-medium
AppType: KernelGateway
DomainId: !GetAtt StudioDomain.DomainId
ResourceSpec:
InstanceType: ml.t3.medium
SageMakerImageArn: !FindInMap
- RegionMap
- !Ref 'AWS::Region'
- datascience
UserProfileName: !Ref UserProfileName
### S3 Bucket similar to the one created by the create domain action in the UI
StudioBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join
- "-"
- - "sagemaker-studio"
- !Select
- 0
- !Split
- "-"
- !Select
- 2
- !Split
- "/"
- !Ref "AWS::StackId"
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled
A2IBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Join
- "-"
- - "idp-a2i"
- !Select
- 0
- !Split
- "-"
- !Select
- 2
- !Split
- "/"
- !Ref "AWS::StackId"
CorsConfiguration:
CorsRules:
-
AllowedOrigins:
- "*"
AllowedMethods:
- GET
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
VersioningConfiguration:
Status: Enabled