Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda