-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresources.yaml
630 lines (608 loc) · 22.3 KB
/
resources.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
AWSTemplateFormatVersion: '2010-09-09'
Description: Create Infrastructure to deploy Amazon SageMaker Feature Store for the Expedia Hotel Recommendations dataset.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
- Label:
default: Required Parameters
Parameters:
- AppName
- LambdaCodeBucketName
- LambdaCodeZipFileName
- SageMakerNotebookName
- CustomerInputFeatureGroupName
- DestinationsFeatureGroupName
- DataBucketName
- MLModelBucketName
- FeatureStoreBucketName
- AthenaQueryResultsBucketName
- RawDataDir
- AlwaysRecreateFeatureGroup
- NotebookInstanceType
- TrainingDatasetFileName
- TestDatasetFileName
- ValidationDatasetFileName
- DestinationsDatasetName
- DestinationFeaturesFileName
- TrainingJobInstanceType
- TrainingJobNodeInstanceCount
- ModelEndpointInstanceType
- ModelEndpointInstanceCount
- CustomerInputStreamName
ParameterLabels:
AppName:
default: Name of the overall application
LambdaCodeBucketName:
default: Name of the S3 bucket for holding the zip file of the Lambda code
LambdaCodeZipFileName:
default: Name of the zip file in S3 bucket containing the code for the hotel cluster prediction lambda.
SageMakerNotebookName:
default: Name of SageMaker Notebook Instance
CustomerInputFeatureGroupName:
default: Feature Group name for customer behavior
DestinationsFeatureGroupName:
default: Feature group name for destinations (see Kaggle documentation)
DataBucketName:
default: Name of S3 bucket from which the notebooks read the raw data
FeatureStoreBucketName:
default: Name of S3 bucket containing the offline feature store data
MLModelBucketName:
default: Name of the S3 bucket for holding the ML model binaries
AthenaQueryResultsBucketName:
default: Name of S3 bucket for storing Athena query results
AlwaysRecreateFeatureGroup:
default: Whether or not to delete a feature group if it exists prior to creating it
NotebookInstanceType:
default: Instance type to use for the notebook
RawDataDir:
default: Folder name in the bucket in which the raw data is kept
TrainingDatasetFileName:
default: File containing the training dataset.
TestDatasetFileName:
default: File containing the test dataset.
ValidationDatasetFileName:
default: File containing the validation dataset.
DestinationFeaturesFileName:
default: File containg the destination features dataset.
ModelEndpointInstanceType:
default: Instance type to use for ML model endpoint.
ModelEndpointInstanceCount:
default: Number of node instances for the ML model endpoint.
TrainingJobInstanceType:
default: Instance type to use for ML model training job.
TrainingJobNodeInstanceCount:
default: Number of node instances to use for the ML model training job.
CustomerInputStreamName:
default: Kinesis stream for simulating real-time customer input data.
Parameters:
AppName:
Default: hotel_cluster_prediction
Type: String
AllowedValues: [hotel_cluster_prediction]
Description: Name of the overall application, this is used while creating the ML model endpoint.
SageMakerNotebookName:
Default: featurestore-expedia-notebook-v1
Type: String
Description: Enter name of SageMaker Notebook instance.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])*
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
DestinationsFeatureGroupName:
Default: expedia-destinations
Type: String
Description: Enter customer behavior feature group name.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
CustomerInputFeatureGroupName:
Default: expedia-customer-inputs
Type: String
Description: Enter customer behavior feature group name.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
LambdaCodeBucketName:
Default: expedia-hotel-cluster-prediction-demo-code
Type: String
Description: Enter name of bucket for storing the zip file for Lmabda function code. Some randomness will be appended to the bucket name provided.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
LambdaCodeZipFileName:
Default: hotel_cluster_predictions_v1.zip
Type: String
Description: Enter name of zip file containing the hotel cluster prediction lambda function code.
MLModelBucketName:
Default: expedia-ml-models
Type: String
Description: Enter name of bucket for storing the ML model binaries. Some randomness will be appended to the bucket name provided.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
DataBucketName:
Default: expedia-customer-behavior-data
Type: String
Description: Enter name of bucket customer behavior raw data bucket. Some randomness will be appended to the bucket name provided.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
RawDataDir:
Default: raw_data
Type: String
Description: Enter the name of folder inside the data bucket in which the raw data files will be kept.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](_*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
TrainingDatasetFileName:
Default: train.csv
Type: String
Description: Enter the name of the training dataset.
TestDatasetFileName:
Default: test.csv
Type: String
Description: Enter the name of the test dataset.
ValidationDatasetFileName:
Default: validation.csv
Type: String
AllowedValues: [validation.csv]
Description: Enter the name of the validation dataset.
DestinationFeaturesFileName:
Default: destinations.csv
Type: String
AllowedValues: [destinations.csv]
Description: Enter the name of the file containing the destinations fetures.
FeatureStoreBucketName:
Default: expedia-feature-store-offline
Type: String
Description: Enter name of bucket for offline Expedia feature store. Some randomness will be appended to the bucket name provided.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
AthenaQueryResultsBucketName:
Default: athena-query-results
Type: String
Description: Enter name of bucket for storing Athena query results. Some randomness will be appended to the bucket name provided.
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
AlwaysRecreateFeatureGroup:
Default: false
Type: String
AllowedValues: [true, false]
Description: Enter whether or not you want to recreate feature group everytime the notebook is run.
NotebookInstanceType:
Default: ml.t3.2xlarge
Type: String
AllowedValues: [ml.t3.medium, ml.t3.large, ml.t3.xlarge, ml.t3.2xlarge]
Description: Enter the instance type to use for the notebook. Default is ml.t3.xlarge.
ModelEndpointInstanceType:
Default: ml.m5.xlarge
Type: String
AllowedValues: [ml.m5.xlarge]
Description: Enter the instance type to use for the ML model endpoint. Default is ml.m5.xlarge.
TrainingJobInstanceType:
Default: ml.m5.xlarge
Type: String
AllowedValues: [ml.m5.xlarge]
Description: Enter the instance type to use for running the ML model training job. Default is ml.m5.xlarge.
ModelEndpointInstanceCount:
Default: 2
Type: Number
AllowedValues: [1, 2]
Description: Enter the number of nodes for hosting the ML model endpoint.
TrainingJobNodeInstanceCount:
Default: 2
Type: Number
AllowedValues: [1, 2]
Description: Enter the number of nodes for running the ML model training job.
CustomerInputStreamName:
Default: expedia-customer-input-realtime
Type: String
MinLength: 1
MaxLength: 63
AllowedPattern: ^[a-z0-9](-*[a-z0-9])* # no UPPERCASE due to S3 dependency
ConstraintDescription: Must be lowercase or numbers with a length of 1-63 characters.
Resources:
SageMakerRole:
Type: AWS::IAM::Role
Properties:
Tags:
-
Key: Project
Value: !Ref AppName
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- "sagemaker.amazonaws.com"
Action:
- "sts:AssumeRole"
- Effect: "Allow"
Principal:
Service:
- "kinesisanalytics.amazonaws.com"
Action:
- "sts:AssumeRole"
- Effect: "Allow"
Principal:
Service:
- "lambda.amazonaws.com"
Action:
- "sts:AssumeRole"
- Effect: "Allow"
Principal:
Service:
- "glue.amazonaws.com"
Action:
- "sts:AssumeRole"
- Effect: "Allow"
Principal:
Service:
- "databrew.amazonaws.com"
Action:
- "sts:AssumeRole"
ManagedPolicyArns:
- "arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"
- "arn:aws:iam::aws:policy/AmazonKinesisFullAccess"
- "arn:aws:iam::aws:policy/AmazonKinesisAnalyticsFullAccess"
- "arn:aws:iam::aws:policy/service-role/AWSGlueServiceRole"
- "arn:aws:iam::aws:policy/AmazonS3FullAccess"
- "arn:aws:iam::aws:policy/AWSCodeCommitReadOnly"
- "arn:aws:iam::aws:policy/AWSGlueDataBrewFullAccessPolicy"
- "arn:aws:iam::aws:policy/AmazonAthenaFullAccess"
Policies:
- PolicyName: AdditionalSageMakerPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowCloudFormation
Effect: Allow
Action:
- cloudformation:DescribeStacks
- cloudformation:DescribeStackEvents
Resource: "*"
- Sid: AllowLambdaInvoke
Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:GetFunctionConfiguration
- lambda:UpdateFunctionConfiguration
- lambda:InvokeAsync
- lambda:CreateEventSourceMapping
- lambda:DeleteEventSourceMapping
- lambda:ListEventSourceMappings
Resource: "*"
- Sid: SageMakerTesting
Effect: Allow
Action:
- sagemaker:CreateExperiment
- sagemaker:CreateTrial
- sagemaker:DescribeEndpoint
- sagemaker:DescribeEndpointConfig
- sagemaker:DescribeMonitoringSchedule
- sagemaker:DescribeProcessingJob
- sagemaker:InvokeEndpoint
- sagemaker:ListMonitoringExecutions
- sagemaker:Search
Resource: "*"
- Sid: AllowCloudWatch
Effect: Allow
Action:
- cloudwatch:PutDashboard
- cloudwatch:PutMetricData
- cloudwatch:PutMetricAlarm
- cloudwatch:DeleteAlarms
- cloudwatch:PutDashboard
- cloudwatch:DeleteDashboards
Resource: "*"
- Sid: AllowPassRole
Effect: Allow
Action:
- iam:GetRole
- iam:PassRole
Resource: "*"
- Sid: AllowLogQuery
Effect: Allow
Action:
- logs:StartQuery
- logs:GetQueryResults
Resource:
- "*"
LambdaRole:
Type: AWS::IAM::Role
Properties:
Tags:
-
Key: Project
Value: !Ref AppName
AssumeRolePolicyDocument:
Statement:
- Action:
- sts:AssumeRole
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Version: 2012-10-17
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSLambdaExecute
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AmazonKinesisFullAccess
- arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess
Path: "/"
Policies:
- PolicyName: AdditionalLambdaPolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: AllowCloudFormation
Effect: Allow
Action:
- cloudformation:DescribeStacks
- cloudformation:DescribeStackEvents
Resource: "*"
- Sid: AllowLambdaInvoke
Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:GetFunctionConfiguration
- lambda:UpdateFunctionConfiguration
- lambda:InvokeAsync
- lambda:CreateEventSourceMapping
- lambda:DeleteEventSourceMapping
- lambda:ListEventSourceMappings
Resource: "*"
- Sid: AllowSageMakerInvoke
Effect: Allow
Action:
- sagemaker:CreateExperiment
- sagemaker:CreateTrial
- sagemaker:DescribeEndpoint
- sagemaker:DescribeEndpointConfig
- sagemaker:DescribeMonitoringSchedule
- sagemaker:DescribeProcessingJob
- sagemaker:InvokeEndpoint
- sagemaker:ListMonitoringExecutions
- sagemaker:Search
Resource: "*"
FeatureStorePolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: SageMakerFeatureStorePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: SageMakerFeatureStore
Effect: Allow
Action:
- sagemakerfeaturestore:CreateFeatureGroup
- sagemakerfeaturestore:UpdateFeatureGroup
- sagemakerfeaturestore:DescribeFeatureGroup
- sagemakerfeaturestore:DeleteFeatureGroup
- sagemakerfeaturestore:ListFeatureGroups
- sagemaker:PutRecord
- sagemaker:GetRecord
- sagemaker:DeleteRecord
- featurestore-runtime:PutRecord
- featurestore-runtime:GetRecord
- featurestore-runtime:DeleteRecord
- s3:PutBucketPolicy
- s3:DeleteBucket
- glue:CreateCrawler
- glue:StartCrawler
- glue:GetCrawler
- glue:GetTable
- glue:GetPartitions
- glue:DeleteCrawler
- glue:DeleteDatabase
- athena:StartQueryExecution
- athena:GetQueryExecution
Resource: "*"
Roles:
- !Ref SageMakerRole
- !Ref LambdaRole
S3AccessPolicy:
Type: AWS::IAM::Policy
Properties:
PolicyName: S3FeatureStorePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Sid: FeatureStoreOfflineStoreS3BucketPolicy
Effect: Allow
Action:
- s3:CreateBucket
- s3:GetBucket*
- s3:GetObject*
- s3:ListBucket
- s3:PutObject
- s3:PutObjectAcl
Resource:
- !Sub arn:aws:s3:::sagemaker-${AWS::Region}-${AWS::AccountId}/*
- !Sub arn:aws:s3:::sagemaker-${AWS::Region}-${AWS::AccountId}
- Sid: AllowLogs
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: "*"
Roles:
- !Ref SageMakerRole
- !Ref LambdaRole
SagemakerFeatureStoreNotebook:
Type: "AWS::SageMaker::NotebookInstance"
Properties:
NotebookInstanceName: !Ref SageMakerNotebookName
InstanceType: !Ref NotebookInstanceType
RoleArn: !GetAtt SageMakerRole.Arn
DefaultCodeRepository: "https://github.com/aws-samples/feature-store-end-to-end.git"
Tags:
-
Key: Project
Value: !Ref AppName
MLModelBucket:
Type: 'AWS::S3::Bucket'
Properties:
AccessControl: Private
BucketName: !Sub
- '${MLModelBucketName}-${RandomGUID}'
- { RandomGUID: !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId ]]]] }
Tags:
-
Key: Project
Value: !Ref AppName
RawDataBucket:
Type: 'AWS::S3::Bucket'
Properties:
AccessControl: Private
BucketName: !Sub
- '${DataBucketName}-${RandomGUID}'
- { RandomGUID: !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId ]]]] }
Tags:
-
Key: Project
Value: !Ref AppName
FeatureStoreBucket:
Type: 'AWS::S3::Bucket'
Properties:
AccessControl: Private
BucketName: !Sub
- '${FeatureStoreBucketName}-${RandomGUID}'
- { RandomGUID: !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId ]]]] }
Tags:
-
Key: Project
Value: !Ref AppName
AthenaQueryResultsBucket:
Type: 'AWS::S3::Bucket'
Properties:
AccessControl: Private
BucketName: !Sub
- '${AthenaQueryResultsBucketName}-${RandomGUID}'
- { RandomGUID: !Select [0, !Split ["-", !Select [2, !Split ["/", !Ref AWS::StackId ]]]] }
Tags:
-
Key: Project
Value: !Ref AppName
HotelClusterPredictionFunction:
Type: AWS::Lambda::Function
Properties:
FunctionName: PredictHotelCluster
Description: Lambda function for predicting hotel clusters from customer input (kinesis)
and destination features (feature store) using a SageMaker ML model endpoint.
Runtime: python3.7
Code:
S3Bucket: !Ref LambdaCodeBucketName
S3Key: !Ref LambdaCodeZipFileName
Handler: hotel_cluster_predictions.handler
MemorySize: 512
Timeout: 60
Role: !GetAtt LambdaRole.Arn
Tags:
-
Key: Project
Value: !Ref AppName
-
Key: Version
Value: v3
Environment:
Variables:
ENDPOINT_NAME: this_will_be_overwritten_by_notebook
FG_NAME: this_will_be_overwritten_by_notebook
DDB_TABLE_NAME: this_will_be_overwritten_by_notebook
ONLINE_FEATURE_GROUP_KEY: this_will_be_overwritten_by_notebook
ONLINE_FEATURE_GROUP_FEATURES_OF_INTEREST: this_will_be_overwritten_by_notebook
PREDICTED_VARIABLE: this_will_be_overwritten_by_notebook
ExpediaCustomerInputStream:
Type: AWS::Kinesis::Stream
Properties:
Name: !Ref CustomerInputStreamName
RetentionPeriodHours: 24
ShardCount: 1
StreamEncryption:
EncryptionType: KMS
KeyId: alias/aws/kinesis
Tags:
-
Key: Project
Value: !Ref AppName
CustomerInputStreamToPredictionLambdaMapping:
Type: AWS::Lambda::EventSourceMapping
Properties:
EventSourceArn:
Fn::Join:
- ""
-
- "arn:aws:kinesis:"
-
Ref: "AWS::Region"
- ":"
-
Ref: "AWS::AccountId"
- ":stream/"
-
Ref: "CustomerInputStreamName"
FunctionName:
Fn::GetAtt:
- "HotelClusterPredictionFunction"
- "Arn"
StartingPosition: "LATEST"
HotelClusterPredictionsTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ExpediaPerCustomerHotelClusterPredictions
AttributeDefinitions:
-
AttributeName: user_id
AttributeType: "S"
-
AttributeName: date_time
AttributeType: "S"
KeySchema:
-
AttributeName: user_id
KeyType: HASH
-
AttributeName: date_time
KeyType: RANGE
ProvisionedThroughput:
ReadCapacityUnits: 5
WriteCapacityUnits: 5
Tags:
-
Key: Project
Value: !Ref AppName
Outputs:
SagemakerFeatureStoreNotebookId:
Value: !Ref SagemakerFeatureStoreNotebook
Description: Arn of the Jupyter notebook created for running the demo code.
DataBucketName:
Value: !Ref RawDataBucket
Description: Name of the S3 bucket containing feature store demo data.
MLModelBucketName:
Value: !Ref MLModelBucket
Description: Name of the S3 bucket containing the ML model binaries.
FeatureStoreBucketName:
Value: !Ref FeatureStoreBucket
Description: Name of the S3 bucket containing feature store demo data.
AthenaQueryResultsBucketName:
Value: !Ref AthenaQueryResultsBucket
Description: Name of the S3 bucket containing feature store demo data.
HotelClusterPredictionFunction:
Value: !GetAtt HotelClusterPredictionFunction.Arn
Description: Arn of the hotel cluster prediction lambda function.
HotelClusterPredictionsTableName:
Value: !Ref HotelClusterPredictionsTable
Description: Name of the DynamoDB table containing the hotel cluster predictions