Skip to content

Commit e27f62f

Browse files
authored
Update README.md
1 parent 47567c1 commit e27f62f

File tree

1 file changed

+220
-0
lines changed

1 file changed

+220
-0
lines changed

README.md

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,3 +180,223 @@ resources:
180180
plugins:
181181
- serverless-step-functions
182182
```
183+
## Sample statemachines setting in serverless.yml
184+
### Waite State
185+
``` yaml
186+
custom:
187+
accountId: <Here is your accountId>
188+
189+
functions:
190+
hello:
191+
handler: handler.hello
192+
193+
stepFunctions:
194+
stateMachines:
195+
yourWateMachine:
196+
definition:
197+
Comment: "An example of the Amazon States Language using wait states"
198+
StartAt: FirstState
199+
States:
200+
FirstState:
201+
Type: Task
202+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello
203+
Next: wait_using_seconds
204+
wait_using_seconds:
205+
Type: Wait
206+
Seconds: 10
207+
Next: wait_using_timestamp
208+
wait_using_timestamp:
209+
Type: Wait
210+
Timestamp: '2015-09-04T01:59:00Z'
211+
Next: wait_using_timestamp_path
212+
wait_using_timestamp_path:
213+
Type: Wait
214+
TimestampPath: "$.expirydate"
215+
Next: wait_using_seconds_path
216+
wait_using_seconds_path:
217+
Type: Wait
218+
SecondsPath: "$.expiryseconds"
219+
Next: FinalState
220+
FinalState:
221+
Type: Task
222+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello
223+
End: true
224+
```
225+
226+
### Retry Failture
227+
``` yaml
228+
custom:
229+
accountId: <Here is your accountId>
230+
231+
functions:
232+
hello:
233+
handler: handler.hello
234+
235+
stepFunctions:
236+
stateMachines:
237+
yourRetryMachine:
238+
definition:
239+
Comment: "A Retry example of the Amazon States Language using an AWS Lambda Function"
240+
StartAt: HelloWorld
241+
States:
242+
HelloWorld:
243+
Type: Task
244+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello
245+
Retry:
246+
- ErrorEquals:
247+
- HandledError
248+
IntervalSeconds: 1
249+
MaxAttempts: 2
250+
BackoffRate: 2
251+
- ErrorEquals:
252+
- States.TaskFailed
253+
IntervalSeconds: 30
254+
MaxAttempts: 2
255+
BackoffRate: 2
256+
- ErrorEquals:
257+
- States.ALL
258+
IntervalSeconds: 5
259+
MaxAttempts: 5
260+
BackoffRate: 2
261+
End: true
262+
```
263+
264+
### Parallel
265+
266+
```yaml
267+
custom:
268+
accountId: <Here is your accountId>
269+
270+
functions:
271+
hello:
272+
handler: handler.hello
273+
274+
stepFunctions:
275+
stateMachines:
276+
yourParallelMachine:
277+
definition:
278+
Comment: "An example of the Amazon States Language using a parallel state to execute two branches at the same time."
279+
StartAt: Parallel
280+
States:
281+
Parallel:
282+
Type: Parallel
283+
Next: Final State
284+
Branches:
285+
- StartAt: Wait 20s
286+
States:
287+
Wait 20s:
288+
Type: Wait
289+
Seconds: 20
290+
End: true
291+
- StartAt: Pass
292+
States:
293+
Pass:
294+
Type: Pass
295+
Next: Wait 10s
296+
Wait 10s:
297+
Type: Wait
298+
Seconds: 10
299+
End: true
300+
Final State:
301+
Type: Pass
302+
End: true
303+
```
304+
305+
### Catch Failture
306+
307+
```yaml
308+
custom:
309+
accountId: <Here is your accountId>
310+
311+
functions:
312+
hello:
313+
handler: handler.hello
314+
315+
stepFunctions:
316+
stateMachines:
317+
yourCatchMachine:
318+
definition:
319+
Comment: "A Catch example of the Amazon States Language using an AWS Lambda Function"
320+
StartAt: HelloWorld
321+
States:
322+
HelloWorld:
323+
Type: Task
324+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello
325+
Catch:
326+
- ErrorEquals:
327+
- HandledError
328+
Next: CustomErrorFallback
329+
- ErrorEquals:
330+
- States.TaskFailed
331+
Next: ReservedTypeFallback
332+
- ErrorEquals:
333+
- States.ALL
334+
Next: CatchAllFallback
335+
End: true
336+
CustomErrorFallback:
337+
Type: Pass
338+
Result: "This is a fallback from a custom lambda function exception"
339+
End: true
340+
ReservedTypeFallback:
341+
Type: Pass
342+
Result: "This is a fallback from a reserved error code"
343+
End: true
344+
CatchAllFallback:
345+
Type: Pass
346+
Result: "This is a fallback from a reserved error code"
347+
End: true
348+
```
349+
350+
### Choice
351+
352+
```yaml
353+
custom:
354+
accountId: <Here is your account Id>
355+
356+
functions:
357+
hello1:
358+
handler: handler.hello1
359+
hello2:
360+
handler: handler.hello2
361+
hello3:
362+
handler: handler.hello3
363+
hello4:
364+
handler: handler.hello4
365+
366+
stepFunctions:
367+
stateMachines:
368+
yourChoiceMachine:
369+
definition:
370+
Comment: "An example of the Amazon States Language using a choice state."
371+
StartAt: FirstState
372+
States:
373+
FirstState:
374+
Type: Task
375+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello1
376+
Next: ChoiceState
377+
ChoiceState:
378+
Type: Choice
379+
Choices:
380+
- Variable: "$.foo"
381+
NumericEquals: 1
382+
Next: FirstMatchState
383+
- Variable: "$.foo"
384+
NumericEquals: 2
385+
Next: SecondMatchState
386+
Default: DefaultState
387+
FirstMatchState:
388+
Type: Task
389+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello2
390+
Next: NextState
391+
SecondMatchState:
392+
Type: Task
393+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello3
394+
Next: NextState
395+
DefaultState:
396+
Type: Fail
397+
Cause: "No Matches!"
398+
NextState:
399+
Type: Task
400+
Resource: arn:aws:lambda:${opt:region}:${self:custom.accountId}:function:${self:service}-${opt:stage}-hello4
401+
End: true
402+
```

0 commit comments

Comments
 (0)