-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserverless.yml
195 lines (183 loc) · 5.57 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
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
service: burst-compute
plugins:
- serverless-bundle
- serverless-step-functions
custom:
version: ${file(./package.json):version}
nodeJSRuntime: nodejs16.x
tracing: false
debug: true
tasksTable: ${self:service}-${self:provider.stage}-tasks
stateMachine: ${self:service}-${self:provider.stage}-lifecycle
defaultJobTimeoutSecs: 60
provider:
name: aws
region: ${opt:region, "us-east-1"}
stage: ${opt:stage, "dev"}
tags:
PROJECT: BurstCompute
VERSION: ${self:custom.version}
DEVELOPER: ${env:USER}
stackTags:
PROJECT: BurstCompute
VERSION: ${self:custom.version}
DEVELOPER: ${env:USER}
STAGE: ${self:provider.stage}
tracing:
lambda: ${self:custom.tracing}
environment:
AWS_NODEJS_CONNECTION_REUSE_ENABLED: 1
iam:
role:
statements:
- Effect: Allow
Action:
- dynamodb:Query
Resource: "arn:aws:dynamodb:${self:provider.region}:*:table/${self:custom.tasksTable}"
- Effect: Allow
Action:
- states:StartExecution
Resource: "arn:aws:states:${self:provider.region}:*:stateMachine:${self:custom.stateMachine}"
- Effect: Allow
Action:
- lambda:InvokeFunction
- lambda:InvokeAsync
Resource: "*"
package:
individually: true
patterns:
- src/main/nodejs/**
functions:
dispatch:
runtime: ${self:custom.nodeJSRuntime}
handler: src/main/nodejs/dispatch.dispatchHandler
memorySize: 256
# 5 minute timeout
timeout: 300
environment:
DEBUG: ${self:custom.debug}
JOB_TIMEOUT_SECS: ${self:custom.defaultJobTimeoutSecs}
DISPATCH_FUNCTION_NAME: ${self:service}-${self:provider.stage}-dispatch
MONITOR_FUNCTION_NAME: ${self:service}-${self:provider.stage}-monitor
STATE_MACHINE_ARN: ${self:resources.Outputs.JobLifecycleStateMachine.Value}
TASKS_TABLE_NAME: ${self:custom.tasksTable}
monitor:
runtime: ${self:custom.nodeJSRuntime}
handler: src/main/nodejs/monitor.monitorHandler
memorySize: 128
timeout: ${self:custom.defaultJobTimeoutSecs}
environment:
DEBUG: ${self:custom.debug}
JOB_TIMEOUT_SECS: ${self:custom.defaultJobTimeoutSecs}
TASKS_TABLE_NAME: ${self:custom.tasksTable}
stepFunctions:
validate: true # enable pre-deployment definition validation
stateMachines:
jobLifecycleStateMachine:
id: JobLifecycleStateMachine
name: ${self:custom.stateMachine}
definition:
Comment: "Monitors a burst compute job and calls the combiner when all tasks are done"
StartAt: Monitor
States:
Monitor:
Type: Task
Resource: arn:aws:states:::lambda:invoke
Parameters:
FunctionName.$: "$$.Execution.Input.monitorFunctionName"
Payload.$: "$"
OutputPath: "$.Payload"
Retry:
- ErrorEquals:
- Lambda.TooManyRequestsException
IntervalSeconds: 1
MaxAttempts: 100
Catch:
- ErrorEquals:
- States.ALL
Next: Combine
Next: IsTimedOut
IsTimedOut:
Type: Choice
Choices:
- Variable: "$.timedOut"
BooleanEquals: true
Next: Combine
Default: AreWeDoneYet
AreWeDoneYet:
Type: Choice
Choices:
- Variable: "$.completed"
BooleanEquals: true
Next: Combine
Default: Wait
Wait:
Type: Wait
Seconds: 1
Next: Monitor
Combine:
Type: Task
Resource: arn:aws:states:::lambda:invoke
Parameters:
FunctionName.$: "$$.Execution.Input.combinerFunctionName"
Payload.$: "$"
OutputPath: "$"
Catch:
- ErrorEquals:
- States.ALL
Next: CombineError
ResultPath: "$.fatalErrors[0]"
Next: EndState
CombineError:
Type: Task
Resource: arn:aws:states:::lambda:invoke
Parameters:
FunctionName.$: "$$.Execution.Input.combinerFunctionName"
Payload.$: "$"
Next: EndState
EndState:
Type: Pass
End: true
resources:
Resources:
TasksTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tasksTable}
KeySchema:
- AttributeName: jobId
KeyType: HASH
- AttributeName: batchId
KeyType: RANGE
AttributeDefinitions:
- AttributeName: jobId
AttributeType: S
- AttributeName: batchId
AttributeType: N
BillingMode: PAY_PER_REQUEST
TimeToLiveSpecification:
AttributeName: ttl
Enabled: "true"
Outputs:
TasksTable:
Description: Name of the tasks table
Value:
"Ref": TasksTable
Export:
Name: BurstComputeTasksTable-${self:provider.stage}
JobLifecycleStateMachine:
Description: The ARN of the state machine
Value:
Ref: JobLifecycleStateMachine
DispatchLambdaFunction:
Description: Name of the dispatch function
Value:
Ref: DispatchLambdaFunction
Export:
Name: BurstComputeDispatchLambdaFunction-${self:provider.stage}
MonitorLambdaFunction:
Description: Name of the monitor function
Value:
Ref: MonitorLambdaFunction
Export:
Name: BurstComputeMonitorLambdaFunction-${self:provider.stage}