Skip to content

Instantly share code, notes, and snippets.

@beabetterdevv
Created September 30, 2022 20:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save beabetterdevv/e93f2e0962948e5b7f196198ffa529db to your computer and use it in GitHub Desktop.
Save beabetterdevv/e93f2e0962948e5b7f196198ffa529db to your computer and use it in GitHub Desktop.
{
"Comment": "A description of my state machine",
"StartAt": "Add Order Entry",
"States": {
"Add Order Entry": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:putItem",
"Parameters": {
"TableName": "CustomerOrdersTable",
"Item": {
"customerId": {
"S.$": "$.customerId"
},
"orderId": {
"S.$": "$.orderId"
}
}
},
"ResultSelector": {
"statusCode.$": "$.SdkHttpMetadata.HttpStatusCode"
},
"ResultPath": "$.result",
"Next": "Choice"
},
"Choice": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.result.statusCode",
"NumericEquals": 200,
"Next": "Call Credit Card Service To Charge Customer"
}
],
"Default": "Fail"
},
"Call Credit Card Service To Charge Customer": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": {
"Payload.$": "$",
"FunctionName": "arn:aws:lambda:us-east-1:755314965794:function:Test:$LATEST"
},
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Next": "Success",
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Fallback - Delete failed order",
"ResultPath": "$.result"
}
],
"ResultPath": "$.result"
},
"Fallback - Delete failed order": {
"Type": "Task",
"Resource": "arn:aws:states:::dynamodb:deleteItem",
"Parameters": {
"TableName": "CustomerOrdersTable",
"Key": {
"customerId": {
"S.$": "$.customerId"
},
"orderId": {
"S.$": "$.orderId"
}
}
},
"Next": "Fail"
},
"Success": {
"Type": "Succeed"
},
"Fail": {
"Type": "Fail"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment