Tuesday, 15 July 2025

Step Function

 

Type

Description

Task

Performs work by invoking a Lambda, ECS, or any supported AWS service

Choice

Adds conditional logic (like if/else or switch-case)

Wait

Waits for a specified time or timestamp before continuing

Pass

Passes input to output unchanged or with a fixed result

Succeed

Terminates the execution successfully

Fail

Terminates the execution with failure

Parallel

Executes multiple branches concurrently and waits for all to complete

Map

Applies a sub-workflow to each element of an array (similar to a loop)




{

  "Comment": "Simple Fund Transfer with Parallel Checks",

  "StartAt": "ParallelChecks",

  "States": {

    "ParallelChecks": {

      "Type": "Parallel",

      "Branches": [

        {

          "StartAt": "BalanceCheck",

          "States": {

            "BalanceCheck": {

              "Type": "Task",

              "Resource": "arn:aws:lambda:region:account-id:function:BalanceCheck",

              "Catch": [

                {

                  "ErrorEquals": ["States.ALL"],

                  "Next": "BalanceCheckFailed"

                }

              ],

              "End": true

            },

            "BalanceCheckFailed": {

              "Type": "Fail",

              "Cause": "Insufficient balance"

            }

          }

        },

        {

          "StartAt": "FraudCheck",

          "States": {

            "FraudCheck": {

              "Type": "Task",

              "Resource": "arn:aws:lambda:region:account-id:function:FraudCheck",

              "Catch": [

                {

                  "ErrorEquals": ["States.ALL"],

                  "Next": "FraudCheckFailed"

                }

              ],

              "End": true

            },

            "FraudCheckFailed": {

              "Type": "Fail",

              "Cause": "Fraud detected"

            }

          }

        }

      ],

      "Next": "TransferFunds"

    },

    "TransferFunds": {

      "Type": "Task",

      "Resource": "arn:aws:lambda:region:account-id:function:TransferFunds",

      "Next": "NotifySuccess",

      "Catch": [

        {

          "ErrorEquals": ["States.ALL"],

          "Next": "TransferFailed"

        }

      ]

    },

    "NotifySuccess": {

      "Type": "Task",

      "Resource": "arn:aws:lambda:region:account-id:function:NotifyCustomerSuccess",

      "End": true

    },

    "TransferFailed": {

      "Type": "Fail",

      "Cause": "Fund transfer failed"

    }

  }

}



Second



{

  "BalanceCheck": {

    "Type": "Task",

    "Resource": "arn:aws:lambda:region:account-id:function:BalanceCheck",

    "Catch": [

      {

        "ErrorEquals": ["States.ALL"],

        "Next": "BalanceCheckFailed"

      }

    ],

    "Next": "IsBalanceSufficient"

  },

  "IsBalanceSufficient": {

    "Type": "Choice",

    "Choices": [

      {

        "Variable": "$.balanceSufficient",

        "BooleanEquals": true,

        "Next": "WaitBeforeFraudCheck"

      }

    ],

    "Default": "BalanceCheckFailed"

  },

  "WaitBeforeFraudCheck": {

    "Type": "Wait",

    "Seconds": 30,

    "Next": "FraudCheck"

  },

  "FraudCheck": {

    "Type": "Task",

    "Resource": "arn:aws:lambda:region:account-id:function:FraudCheck",

    "Catch": [

      {

        "ErrorEquals": ["States.ALL"],

        "Next": "FraudCheckFailed"

      }

    ],

    "Next": "ApproveLoan"

  },

  "ApproveLoan": {

    "Type": "Task",

    "Resource": "arn:aws:lambda:region:account-id:function:ApproveLoan",

    "Next": "NotifyApproval"

  },

  "NotifyApproval": {

    "Type": "Task",

    "Resource": "arn:aws:lambda:region:account-id:function:NotifyApplicantApproval",

    "Next": "LogApproval"

  },

  "LogApproval": {

    "Type": "Task",

    "Resource": "arn:aws:lambda:region:account-id:function:LogApproval",

    "End": true

  },

  "BalanceCheckFailed": {

    "Type": "Fail",

    "Cause": "Insufficient balance or error during balance check"

  },

  "FraudCheckFailed": {

    "Type": "Fail",

    "Cause": "Fraud check failed"

  }

}




No comments:

Post a Comment