简体   繁体   中英

Aws Pass Value from Lambda Trigger to Step Function

使用Lambda函数触发步进函数时,如何获取触发它的函数的输出?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM