Integrate a service into your Step Functions workflow - Amazon Step Functions
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

Integrate a service into your Step Functions workflow

In the previous topic, Create a state machine, you added all the steps to the workflow prototype. Now, you will create and fully integrate a Lambda function into your workflow. You will configure a Task state named Get credit limit which will invoke your Lambda function. Within Task states, you can use any Amazon SDK integrations that Step Functions supports.

To define the first service integration for your workflow, first create your Lambda function. Then, update your workflow to specify the service integration with the Lambda function. The Lambda function used in this tutorial returns a randomly generated integer representing the requested credit limit.

Step 1: Create and test the Lambda function

You can write code for the function in the Amazon Web Services Management Console or your favorite editor. In the following steps, you create a Node.js Lambda function titled RandomNumberforCredit.

Important

Make sure you create the Lambda function in the same region as your state machine in the same Amazon Web Services Region as your state machine.

  1. In a new tab or window, open the Lambda console and create a Node.js Lambda function titled RandomNumberforCredit. For information about creating a Lambda function using the console, see Create a Lambda function in the console in the Amazon Lambda Developer Guide.

  2. On the RandomNumberforCredit page, choose index.mjs and replace the existing code in the Code source area with the following code.

    export const handler = async function(event, context) { const credLimit = Math.floor(Math.random() * 10000); return (credLimit); };
  3. From the Function overview section, copy the Amazon Resource Name of the Lambda function and save it in a text file. You’ll need the function ARN while specifying the service integration for the Get credit limit state. The following is an example ARN:

    arn:aws-cn:lambda:us-west-2:123456789012:function:HelloWorld
  4. Choose Deploy and then choose Test to deploy the changes and see the output of the Lambda function.

Step 2: Update the workflow – configure the Get credit limit state

In the Step Functions console, you’ll update your workflow to specify service integration with the RandomNumberforCredit Lambda function that you created in Step 1.

  1. Open the Step Functions console window containing the workflow prototype you created in Tutorial 1.

  2. Choose the Get credit limit state, and in the Configuration tab, do the following:

    1. For Integration type, keep the default selection of Optimized.

      Using Step Functions, you can integrate with other Amazon Web Services services and orchestrate them in your workflows. For more information about service integrations and their types, see Integrating services with Step Functions.

    2. For Function name, choose the RandomNumberforCredit Lambda function from the dropdown list.

    3. Keep the default selections for rest of the items.

  3. Keep this window open and proceed to the next topic.

Note

You can also use other supported Amazon SDK integrations in the Task state by specifying the service name and API call, as shown in the following example. For information, see Integrating services with Step Functions.

arn:aws-cn:states:::aws-sdk:serviceName:apiAction

Next steps

In the next topic, Add conditional logic you will configure the choice state with conditional logic to determine the next step in the workflow.