Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

152
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda