0

When using a Lambda Function to trigger a Step Function, how do you get the output of the function that triggered it?

1 Answers1

0

Ok, so if you want to pass an input to a Step Function execution (or, more exactly, your 'State Machine''s execution), you just need to set said input the input property when calling StartExecution (see AWS Documentation: Start Execution)

In your case, it would most likely be your lambda's last step before calling it's callback.

If it's a node js lambda, that's what it would look like

const AWS = require("aws-sdk");
const stepfunctions = new AWS.StepFunctions();

exports.myHandler = function(event, context, callback) {

    ... your function's code

    const params = {
       stateMachineArn: 'YOUR_STATE_MACHINE_ARN', /* required */
       input: 'STRINGIFIED INPUT',
       name: 'AN EXECUTION NAME (such as an uuid or whatever)'
    };
    stepfunctions.startExecution(params, function(err, data) {
       if (err) callback(err); // an error occurred
       else     callback(null, "some success message"); // successful response
    });

}

Alternatively, if your payload is too big, you could store the data in S3 or DynamoDB and pass the reference to it as your State Machine's execution's input.

ElFitz
  • 908
  • 1
  • 8
  • 26