1

I'm trying to start the execution of an AWS StepFunction from inside an AWS Lambda, but I receive null as result, with no error message. The StepFunctions here is an Express State Machine, so I use the method startSyncExecution(params = {}, callback), as pointed in the docs.

Here is the code of the Lambda:

const AWS = require('aws-sdk');

exports.handler = async(event, context, callback) => {
    var params = {
        stateMachineArn: "arn:aws:states:us-east-1:[AccountID]:stateMachine:BookLectureStateMachine",
        input: JSON.stringify(event),
        name: "test-from-lambda"
    }
    
    var stepfunctions = new AWS.StepFunctions();

    console.log("Everything okay") //This one is logged

    stepfunctions.startSyncExecution(params, function(err, data) {

        console.log("This log isn't shown"); //This one isn't logged

        if (err) {
            callback(null, {
                statusCode: 400,
                body: err,
                headers: {
                    'Access-Control-Allow-Origin': '*'
                }
            })
        } else {
            callback(null, {
                statusCode: 200,
                body: 'Lecture booked',
                headers: {
                    'Access-Control-Allow-Origin': '*'
                }
            })
        }
    });
};

The response is null, nothing else.

I've checked the permissions, and the Lambda has Full Access to the Step Functions.

Any idea on how to solve it?

UPDATE

  1. I think the StepFunction is not executed, since the logs are empty.
  2. I increased the Lambda timeout to 1min in order to avoid timeout scenarios. The billed duration is about half a second
4
  • Is there anything else in the logs? Like something saying the function timed out? Commented Sep 1, 2021 at 14:46
  • Nope, I increased the timeout to one minute in order to avoid this scenario, and it doesn't expire. I update the question Commented Sep 1, 2021 at 14:49
  • 1
    I think it may have something to do with the mix of callbacks and async. Since you aren't using await in your handler anywhere, I would try removing async from the handler. Either that or you could try changing the code to var data = await stepfunctions.startSyncExecution(params).promise() Commented Sep 1, 2021 at 14:57
  • @MarkB It worked after removing the async. Post it as an answer! Commented Sep 1, 2021 at 15:02

1 Answer 1

2

I believe it may have something to do with the mix of callbacks and async. Since you aren't using await in your handler anywhere, I would try removing async from the handler.

Either that or you could try changing the code to:

var data = await stepfunctions.startSyncExecution(params).promise()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.