codetheweb / serverless-step-functions-local

Run AWS step functions offline with Serverless
MIT License
17 stars 17 forks source link

Any work-around for async lambda handlers ? #4

Closed stall84 closed 3 years ago

stall84 commented 3 years ago

I'm having a lot of trouble getting a lambda as simple as module.exports.handler = async (event) => { const obj = { key: 'value' } return obj; } I also can't get a callback handler to work with anything in the 2nd argument module.exports.handler = (event, context, callback) => { const num = 3 callback(null, { number: num }) }

In both above cases when trying to execute a 2nd task lambda (or any other state for that matter), the step function never exits the first task. It will do any functions called within the lambda, like console logging . . But as soon as I try to return anything from an async or add a 2nd argument to a sync callback .. it never moves to the next state

What am I doing wrong ?

stall84 commented 3 years ago

Just for some more context I made this post on SO with better code snippets and yaml and all https://stackoverflow.com/questions/68228019/offline-local-step-function-task-lambda-not-returning-its-output-and-freezes-st

codetheweb commented 3 years ago

To be completely honest, I have no clue. It's been a few years since I used this package and while it should still work I haven't been dogfeeding it myself at all.

Would either of these alternative packages work?

If so, I'll go ahead and deprecate this in favor of those.

stall84 commented 3 years ago

To be completely honest, I have no clue. It's been a few years since I used this package and while it should still work I haven't been dogfeeding it myself at all.

Would either of these alternative packages work?

* https://github.com/vkkis93/serverless-step-functions-offline

* https://www.npmjs.com/package/serverless-step-functions-offline-async

If so, I'll go ahead and deprecate this in favor of those.

Thanks for the reply man .. Oddly enough I was having the exact same problem with the serverless-step-functions-offline package .. then moved over here b/c it seemed to be a bit newer.. but both are 2 and 3 years old respectively now. I'm going through the code of serverless-offline-lambda now (also 2 years old since update) and trying to figure out what exactly is happening at the point that I return something out of the lambda ... but so far still can't figure it out ..

Thanks again !

stall84 commented 3 years ago

I'm going to give that sls-stpfncs-offln-async package a try .. Thanks for the help. If you want me to close this I will .. But might be worth leaving it open in case anyone else comes across the issue since you're deprecating it.

SOLUTION Found using the serverless-step-functions-offline-async package.. You have to use a callback inside your async lambda, but it DOES solve the problem.

codetheweb commented 3 years ago

👍 glad you got it working.