How can I create a Step Function with two Lambda tasks passing data between them and set up the required execution role, including any recommended naming conventions

I want to create a Step Function with two tasks, each corresponding to a Lambda function, where the output of the first Lambda function serves as the input to the second Lambda function. How can I create and associate a Step Functions execution role that allows the Step Function to invoke the Lambda functions? Is there a specific naming convention or pattern I should follow when creating this role? Please guide me on how to set this up.

1 Like

If the issue is needing to create a role for setting up your lambda, please look at the guide page in our FAQ. Our AWS privileges certain role names, so choose from the suggested patterns.

You can achieve this setup in AWS Step Functions by defining a workflow with two Lambda tasks connected sequentially. The output of the first Lambda function becomes the input of the second Lambda function through the Step Functions state definition.

Here’s how you can set it up:

1: Create two Lambda functions

  • Function A (first task): processes the initial input.
  • Function B (second task): receives the output from Function A.

2: Create an IAM Role for Step Functions

  • In the AWS Management Console, go to IAM → Roles → Create Role.
  • Choose Step Functions as the trusted entity.
  • Attach the AWSLambdaRole or a custom policy that includes:
{
  "Effect": "Allow",
  "Action": "lambda:InvokeFunction",
  "Resource": "arn:aws:lambda:<region>:<account-id>:function:*"
}
  • Recommended naming convention:
    Use a clear, descriptive name such as StepFn_InvokeLambda_Role or StepFn-NetProcessing-Role.
    This helps identify the role’s purpose easily in multi-service environments.

3: Define the Step Function
Example definition (in JSON):

{
  "Comment": "Step Function with two Lambda tasks",
  "StartAt": "FirstTask",
  "States": {
    "FirstTask": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:LambdaFunctionA",
      "Next": "SecondTask"
    },
    "SecondTask": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:LambdaFunctionB",
      "End": true
    }
  }
}

4: Data passing
Step Functions automatically passes the result of one state to the next.
You can control this using ResultPath, InputPath, or OutputPath fields if you need to filter or reshape the data between steps.

5: Test the workflow
Deploy your state machine, provide sample input, and verify that the output from the first Lambda function correctly flows into the second one.

You can check out the official AWS Step Functions documentation — it has a great example of chaining Lambda functions and setting up the IAM execution role. Here’s a good starting point: AWS Step Functions Tutorial: Using AWS Lambda Functions. It walks through role creation and permissions in detail.