Express mock of lambda/Api Gateway for local testing?

Hi All,

I’m trying to create a serverless backend for a react frontend SPA. One thing I realized that’s less than ideal is being able to “test” things manually on my local machine. Currently there is no way to run function other than invoke local. I am just thinking, has someone written an simple express server than essentially mocks the API gateway and can invoke the functions locally (translating say an express request to sls request and so on).

In addition to that, I can imagine that it could read the serverless.yml file and automatically generate the endpoints. For example, one format would be: http://localhost:3000/serverless/{stage}/{event_type}/{function}). If event type is S3, then we just force POST and require json body to “mock” out the event.

Has anyone seen anything or working on this? If so let me know.

Frank

Have a look at the serverless-offline plugin.

And if you use dynamodb, there is the serverless-dynamodb-local plugin as well.

Hope it helps.

1 Like

Yep. This is exactly what I’m looking for. Thanks!

Thanks, but it only works with NodeJS, while I’m using Python 3.6.

Actually even such basic invoke local functionality would be good, but it needs a way so that I can convert a JSON request body into the event’s body string… rather automatically.

serverless-offline plugin seems to be cool, I don’t know why it has to be NodeJS-only. :frowning: I think what it does is preparing the “event” object to mimic API gateway’s, so API gateway can do this regardless of language, I don’t get why it requires a specific language…

Update: This seems interesting: https://serverless.com/framework/docs/platform/commands/#serverless-run (via @alexbdebrie https://twitter.com/alexbdebrie/status/900373779003580416 )
Update 2: NOTE: currently supports node js 6.3+ only :frowning: