-
Notifications
You must be signed in to change notification settings - Fork 1
/
wrapper-lambda-functions.yaml
127 lines (111 loc) · 4.01 KB
/
wrapper-lambda-functions.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
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Create AWS Lambda functions and IAM roles to interface with Amazon Personalize for Customer Intent Prediction Blog Article"
Transform: AWS::Serverless-2016-10-31
Parameters:
ResourceBucket:
Type: String
Description: S3 Bucket where the Resources are stored (cloudformation, data files, lambda code)
ResourceBucketKeyForGetRecommentationLambdaFunction:
Type: String
Description: S3 Bucket Path to the personalized-intent lambda function package (zip)
ResourceBucketKeyForUpdateEventLambdaFunction:
Type: String
Description: S3 Bucket Path to the update-real-time-customer-interactions lambda function package (zip)
PersonalizeRegion:
Type: String
Default: us-east-1
AllowedValues :
- us-east-1
Description: The region where the personalize service is deployed.
PredictionConfidenceScoreHighThreshold:
Type: Number
Default: 0.80
AllowedValues :
- 0.90
- 0.85
- 0.80
Description: Minimum confidence score required to use customer intent prediction from Personalize service
PredictionConfidenceScoreLowThreshold:
Type: Number
Default: 0.60
AllowedValues :
- 0.60
- 0.65
- 0.70
Description: Minimum confidence score required to use customer intent prediction from Personalize service
PersonalizeCampaignARN:
Type: String
Description: ARN of the deployed personalize campaign
PersonalizeModelTrackingID:
Type: String
Description: Trackign ID of the deployed personalize model
Resources:
LambdaFunctionRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: "/service-role/"
Policies:
-
PolicyName: LambdaPersonalizePolicy
PolicyDocument:
Version: "2012-10-17"
Statement:
-
Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource:
- !Sub "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:/aws/lambda/*:*:*"
-
Effect: Allow
Action:
- personalize:PutEvents
- personalize:GetRecommendations
Resource: "*"
GetRecommendationFunction:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Sub "${AWS::StackName}-get-personalized-intent"
Handler: lambda_function.lambda_handler
CodeUri:
Bucket: !Ref ResourceBucket
Key: !Ref ResourceBucketKeyForGetRecommentationLambdaFunction
Description: Function for getting recommendation from the personalize service
Runtime: python3.7
Environment:
Variables:
REGION: !Ref PersonalizeRegion
HIGH_CONFIDENCE_THRESHOLD: !Ref PredictionConfidenceScoreHighThreshold
MID_CONFIDENCE_THRESHOLD: !Ref PredictionConfidenceScoreLowThreshold
PERSONALIZE_CAMPAIGN_ARN: !Ref PersonalizeCampaignARN
Role: !GetAtt LambdaFunctionRole.Arn
Timeout: 300
PutEventsFunction:
Type: "AWS::Serverless::Function"
Properties:
FunctionName: !Sub "${AWS::StackName}-update-real-time-customer-interactions"
Handler: lambda_function.lambda_handler
CodeUri:
Bucket: !Ref ResourceBucket
Key: !Ref ResourceBucketKeyForUpdateEventLambdaFunction
Description: Function for updating customer interaction data in real-time to the personalize service
Runtime: python3.7
Environment:
Variables:
REGION: !Ref PersonalizeRegion
PERSONALIZE_MODEL_TRACKING_ID: !Ref PersonalizeModelTrackingID
Role: !GetAtt LambdaFunctionRole.Arn
Timeout: 300