Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
How to pass a variable into catch statement in AWS Step Functions

I develop a very simple workflow in AWS Step Functions like the below picture.

enter image description here

CreateNewItem function creates a new record in Dynamo DB, then if it fails, the Create NewItemFail function calls.

CreateNewItemFail function sends an email including information about the data the first function tried to insert into Dynamo DB.

However, I have no idea how to throw a variable into the failer function.

This is the handler function code of the CreateNewItem function.

const AWS = require('aws-sdk')

AWS.config.update({
    region: "ap-northeast-1",
})
const dynamoDb = new AWS.DynamoDB();
const table = "ItemTable";

exports.handler = async(event, context, callback) => {
    const item = {
        id: 'xxxxxxxxxx',
        name: 'hello',
    }

    try {

        //
        // Insert data(item) into Dynamo DB here.
        //

    } catch(e) {
        const createItemError = new Error('Insert data error');
        createItemError.name = "CreateItemError";

        // here, I would like to know how to pass the `item` variable. 
        throw createItemError;
    }

    const response = {
        statusCode: 200,
        body: JSON.stringify('Hello from Lambda!'),
    };
    return response;
};

The CreateNewItemFail function's input is this.

{
  "Error": "CreateItemError",
  "Cause": "{\"errorType\":\"CreateItemError\",\"errorMessage\":\"Insert data error\",\"trace\":[\"CreateItemError: Insert data error\",\"    at Runtime.exports.handler (/var/task/index.js:147:28)\",\"    at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)\"]}"
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!