Skip to content

Instantly share code, notes, and snippets.

@mariobittencourt
Last active January 30, 2021 14:39
Show Gist options
  • Save mariobittencourt/c4b0a0f863ed327a96fbb89b1b30df6f to your computer and use it in GitHub Desktop.
Save mariobittencourt/c4b0a0f863ed327a96fbb89b1b30df6f to your computer and use it in GitHub Desktop.
Step Function: full flow
{
"StartAt": "Create Order In Pending",
"States": {
"Create Order In Pending": {
"Next": "Authenticate Payment",
"Type": "Task",
"Comment": "Creates the order in pending state",
"ResultPath": "$.order",
"Resource": "arn:aws:lambda:us-east-1:*******:function:create-order-in-pending",
"Parameters": {
"amount.$": "$.amount",
"sku.$": "$.sku",
"quantity.$": "$.quantity"
}
},
"Authenticate Payment": {
"Next": "Reserve Item",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
},
{
"ErrorEquals": [
"Payment.GatewayUnavailable",
],
"IntervalSeconds": 5,
"MaxAttempts": 5,
"BackoffRate": 3
}
],
"Catch": [
{
"ErrorEquals": [
"Payment.UnsufficientFunds", "Payment.InvalidCard"
],
"ResultPath": "$.authenticationError",
"Next": "Mark Order as Cancelled"
}
],
"Type": "Task",
"ResultPath": "$.paymentAuthentication",
"Resource": "arn:aws:lambda:us-east-1:********:function:order-auth-payment",
"Parameters": {
"amount.$": "$.order.amount"
}
},
"Reserve Item": {
"Next": "Capture Payment",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"Next": "Release Authentication"
}
],
"Type": "Task",
"InputPath": "$.order",
"ResultPath": "$.stockAllocation",
"Resource": "arn:aws:lambda:us-east-1:******:function:order-reserve-item"
},
"Capture Payment": {
"Next": "Ship Order",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.captureError",
"Next": "Release Item"
}
],
"Type": "Task",
"InputPath": "$.paymentAuthentication",
"ResultPath": "$.paymentCapture",
"Resource": "arn:aws:lambda:us-east-1:*******:function:order-capture-payment"
},
"Ship Order": {
"Next": "Mark Order As Shipped",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.shippingError",
"Next": "Refund Payment"
}
],
"Type": "Task",
"InputPath": "$.order",
"ResultPath": "$.shipOrder",
"Resource": "arn:aws:lambda:us-east-1:*******:function:order-ship-order"
},
"Mark Order As Shipped": {
"End": true,
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"Comment": "Updates the order to shipped state",
"InputPath": "$.order",
"ResultPath": "$.order",
"Resource": "arn:aws:lambda:us-east-1:********:function:mark-order-shipped"
},
"Refund Payment": {
"Next": "Release Item",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"InputPath": "$.paymentAuthentication",
"ResultPath": "$.paymentRefund",
"Resource": "arn:aws:lambda:us-east-1:********:function:order-refund-payment"
},
"Release Item": {
"Next": "Mark Order as Cancelled",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"InputPath": "$.order",
"ResultPath": "$.stockDeallocation",
"Resource": "arn:aws:lambda:us-east-1:********:function:order-release-item"
},
"Mark Order as Cancelled": {
"Type": "Task",
"InputPath": "$.order",
"Resource": "arn:aws:lambda:us-east-1:********:function:order-cancel-order"
"ResultPath": "$.order",
"End": true
},
"Release Authentication": {
"Next": "Mark Order as Cancelled",
"Retry": [
{
"ErrorEquals": [
"Lambda.ServiceException",
"Lambda.AWSLambdaException",
"Lambda.SdkClientException"
],
"IntervalSeconds": 2,
"MaxAttempts": 6,
"BackoffRate": 2
}
],
"Type": "Task",
"InputPath": "$.paymentAuthentication",
"ResultPath": "$.paymentReleaseAuthentication",
"Resource": "arn:aws:lambda:us-east-1:********:function:order-release-auth-payment"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment