When using a Lambda Function to trigger a Step Function, how do you get the output of the function that triggered it?
Asked
Active
Viewed 1,592 times
0
-
Do you want to pass said output to the Step Function or somewhere else ? – ElFitz Aug 29 '18 at 14:42
-
To the step function – Jim Johnson Aug 30 '18 at 10:29
1 Answers
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