I develop a very simple workflow in AWS Step Functions like the below picture.
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)\"]}"
}