aws / aws-lambda-runtime-interface-emulator

Apache License 2.0
936 stars 99 forks source link

Emulate API Gateway payload in event object #64

Open ndavies-om1 opened 2 years ago

ndavies-om1 commented 2 years ago

We run our lambdas behind an API Gateway. The event object in the lambda when we run locally does not have the same structure as the event object when running behind an API Gateway.

For example, if I want to post to a path with the /{model} parameter, I need to post with this wrapping my payload

{
    "pathParameters": {
        "model": model
    },
    "body": { .. json payload ...}
}

When I call my API Gateway endpoint I do not need to wrap the payload, as this is created by API Gateway as it passes the payload off to the lambda.

What I would really like is to be able to set an ENV var such as LAMBDA_MODE which when set to API_GATEWAY RIE wraps the event to mimic the event passed by the API Gateway. It would need to work the same for response objects too. If not set, then it would work in the default mode which is how it works today.

ndavies-om1 commented 2 years ago

I know I could solve this problem by running a second container that actually takes the API call on another port, wraps the payload and passes it on to RIE. This could be done by a container running nginx + lua

mnapoli commented 1 year ago

I built this project to solve this problem (partially): https://github.com/brefphp/local-api-gateway

OlivierKessler01 commented 1 year ago

This also exists : https://github.com/eagletmt/aws-lambda-rie-gateway

Hoping the project doesn't die