0

I have a Lambda POST function, I'm sending a json body for testing as:

{
  "id": 3
}

But I don't know how to read that body on my code.

At first I had a GET API, I called that API with:

POST: https://XXX.execute-api.us-east-2.amazonaws.com/dev/getData/123 (Content-Type: application/json)

so in my code I had:

export const handler = async (
  event: { pathParameters: { ID: any } }
): Promise<any> => {
    console.log(event.pathParameters.ID) // 123

serverless.yml was:

functions:
  feelookup:
    handler: src/functions/getData.handler
    events:
      - http:
          path: /getData
          method: get
          cors: true

But now I don't know how to read the body on POST

Edit: I tried by event.body but it doesn't existe body.

Here I have console.logs of event and args (from CloudWatch):

export const handler = async (
  event: any,
  args: any,
): Promise<any> => {
  console.log('event', event);
  console.log('args: ', args);

enter image description here

pmiranda
  • 7,602
  • 14
  • 72
  • 155

1 Answers1

0
  1. Check if you have chosen lambda proxy integration or lambda integration in the api gateway.
  2. Might need to use JSON.parse(event.body).
Harsha Limaye
  • 915
  • 9
  • 29