Passing event from API gateway to Lambda

10,246

You don't need an response model.

When you use a lambda proxy in API gateway you get the data in specific form (https://serverless.com/framework/docs/providers/aws/events/apigateway/#example-lambda-proxy-event-default) for full details.

Unlike invoking directly where the handler(event, ctx, callback) function allows you to simply do const payload = event to get the data you were testing with; you will need to do const payload = JSON.parse(event.body), as the event argument contains significantly more information about the full http request.

Share:
10,246
rodrigocf
Author by

rodrigocf

Updated on June 29, 2022

Comments

  • rodrigocf
    rodrigocf about 2 years

    I have a lambda function that can received JSON in many different forms. The idea is to receive that through API Gateway. When i test the function given any form of JSON, it works fine. However, when i try to test it through API Gateway, it fails because the event is empty.

    I tried to add an empty model mapping:

    {}
    

    But i still get the same result. How can I make the API pass any type of JSON in the body to the function?

    Thanks!

    EDIT

    I want to use Lambda Proxy integration and i have testing with postman and the API gateway test feature in the AWS console. I'm just doing a POST with the required JSON in the body and the content type headers.

    enter image description here

  • rodrigocf
    rodrigocf over 5 years
    I would assume the same applies for python then? Python receives event and context.
  • thomasmichaelwallace
    thomasmichaelwallace over 5 years
    Oh- sorry- don't know why I assumed node. But yes, the event is always the same shape no matter what the language. Annoyingly I've never found a very comprehensive list of events, but this is the closest: docs.aws.amazon.com/lambda/latest/dg/eventsources.html