# Express mock of lambda/Api Gateway for local testing?

**URL:** <https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839>\
**Category:** Serverless Framework\
**Created:** [May 10, 2017, 6:30pm UTC](https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839 "2017-05-10T18:30:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gniquil](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gniquil/32/643_2.png) [@gniquil](https://forum.serverless.com/u/gniquil)\
**Post date:** [May 10, 2017, 6:30pm UTC](https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839/1 "2017-05-10T18:30:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bfieber](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/bfieber/32/653_2.png) [@bfieber](https://forum.serverless.com/u/bfieber)\
**Post date:** [May 10, 2017, 7:54pm UTC](https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839/2 "2017-05-10T19:54:26Z")

</div>

Have a look at the [serverless-offline plugin](https://github.com/dherault/serverless-offline).

And if you use dynamodb, there is the [serverless-dynamodb-local plugin](https://github.com/99xt/serverless-dynamodb-local) as well.

Hope it helps.

---

<div class="post-metadata">

**Author:** ![gniquil](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gniquil/32/643_2.png) [@gniquil](https://forum.serverless.com/u/gniquil)\
**Post date:** [May 10, 2017, 11:59pm UTC](https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839/3 "2017-05-10T23:59:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ceefour](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/ceefour/32/911_2.png) [@ceefour](https://forum.serverless.com/u/ceefour)\
**Post date:** [August 24, 2017, 11:14am UTC](https://forum.serverless.com/t/express-mock-of-lambda-api-gateway-for-local-testing/1839/4 "2017-08-24T11:14:08Z")

</div>

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. ☹ 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](https://serverless.com/framework/docs/platform/commands/#serverless-run) (via @alexbdebrie [https://twitter.com/alexbdebrie/status/900373779003580416](https://twitter.com/alexbdebrie/status/900373779003580416) )  
Update 2: NOTE: currently supports node js 6.3+ only ☹
