Skip to content

Instantly share code, notes, and snippets.

@codecitizen
Created November 23, 2018 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecitizen/2e939c85b19dd96f0a607a7d34630d7b to your computer and use it in GitHub Desktop.
Save codecitizen/2e939c85b19dd96f0a607a7d34630d7b to your computer and use it in GitHub Desktop.
AWS Step Functions with Serverless Example, including Re-Try policy, Parallel Execution and Error Handling.
service: aws-step-functions-showcase
provider:
name: aws
runtime: nodejs8.10
iamRoleStatements:
- Effect: "Allow"
Action:
- "states:StartExecution"
Resource:
- "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:stateMachine:PDFTransform"
- Effect: "Allow"
Action:
- "states:DescribeExecution"
Resource:
- "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:execution:PDFTransform:*"
functions:
trigger:
handler: handler.trigger
events:
- http: POST /trigger
environment:
STATE_MACHINE_ARN: "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:stateMachine:PDFTransform"
status:
handler: handler.status
events:
- http: GET /trigger
environment:
EXECUTION_ARN: "arn:aws:states:#{AWS::Region}:#{AWS::AccountId}:execution:PDFTransform:"
convert:
handler: handler.convert
transform:
handler: handler.transform
thumbnail:
handler: hander.thumbnail
rollback:
handler: handler.rollback
stepFunctions:
stateMachines:
pdfTransform:
name: PDFTransform
Description: "Takes vectorised PDFs and transforms them to PNGs with transparentbackground, also generates thumbnails for them."
definition:
StartAt: Convert
States:
Convert:
Type: Task
Next: Processing
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:my-service-${opt:stage}-convert
Retry:
- ErrorEquals:
- States.TaskFailed
IntervalSeconds: 30
MaxAttempts: 2
BackoffRate: 2
Processing:
Type: Parallel
End: true
Catch:
- ErrorEquals:
- States.TaskFailed
Next: Rollback
Branches:
- StartAt: Transform
States:
Transform:
Type: Task
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:my-service-${opt:stage}-transform
End: true
- StartAt: Thumbnail
States:
Thumbnail:
Type: Task
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:my-service-${opt:stage}-thumbnail
End: true
Rollback:
Type: Task
Resource: arn:aws:lambda:#{AWS::Region}:#{AWS::AccountId}:function:my-service-${opt:stage}-rollback
End: true
plugins:
- serverless-step-functions
- serverless-pseudo-parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment