-
Notifications
You must be signed in to change notification settings - Fork 4.5k
/
serverless.yml
137 lines (133 loc) · 3.58 KB
/
serverless.yml
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
service: aws-ruby-step-functions-with-callback
frameworkVersion: '2'
provider:
name: aws
region: us-east-1
runtime: ruby2.7
memorySize: 256
timeout: 10
logRetentionInDays: 30
lambdaHashingVersion: 20201221
iam:
role:
statements:
- Effect: Allow
Action:
- states:SendTaskFailure
- states:SendTaskSuccess
Resource:
- '*'
- Effect: Allow
Action:
- comprehend:DetectPiiEntities
Resource:
- '*'
- Effect: Allow
Action:
- dynamodb:PutItem
Resource:
- !GetAtt Table.Arn
functions:
check-comment:
handler: src/handlers/check_comment/handler.run
environment:
region: ${self:provider.region}
redact-comment:
handler: src/handlers/redact_comment/handler.run
plugins:
- serverless-ruby-layer
- serverless-step-functions
custom:
stateMachineName: workflow-with-callback-${sls:stage}
tableName: ${self:service}-${sls:stage}
rubyLayer:
include_functions:
- check-comment
- redact-comment
resources:
Resources:
Table:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tableName}
Tags:
- Key: Application
Value: ${self:service}
- Key: Stage
Value: ${sls:stage}
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
stepFunctions:
stateMachines:
WorkflowWithCallback:
name: ${self:custom.stateMachineName}
events:
- http:
path: comments/add
method: POST
definition:
StartAt: Pass Params
States:
Pass Params:
Type: Pass
Next: Run Detection
Parameters:
comment.$: $.comment
author.$: $.author
Run Detection:
Type: Task
Resource: arn:aws:states:::lambda:invoke.waitForTaskToken
Parameters:
FunctionName:
Fn::GetAtt: [check-comment, Arn]
Payload:
task_token.$: $$.Task.Token
comment.$: $.comment
Retry:
- ErrorEquals:
- Lambda.ServiceException
- Lambda.AWSLambdaException
- Lambda.SdkClientException
IntervalSeconds: 2
MaxAttempts: 6
BackoffRate: 2
ResultPath: $.result
Next: Is Detection Result
Is Detection Result:
Type: Choice
Choices:
- Variable: $.result
StringEquals: No result
Next: Save to DB
Default: Redact Comment
Redact Comment:
Type: Task
Resource:
Fn::GetAtt: [redact-comment, Arn]
ResultPath: $.comment
Retry:
- ErrorEquals:
- Lambda.ServiceException
- Lambda.AWSLambdaException
- Lambda.SdkClientException
IntervalSeconds: 2
MaxAttempts: 6
BackoffRate: 2
Next: Save to DB
Save to DB:
Type: Task
Resource: arn:aws:states:::dynamodb:putItem
Parameters:
TableName: ${self:custom.tableName}
Item:
id:
S.$: $.author
comment:
S.$: $.comment
End: true
validate: true