Access HTTP request (headers, query string, cookies, body) object in lambda with http endpoint

后端 未结 4 1395
忘掉有多难
忘掉有多难 2021-02-13 23:00

I am trying to see how to access the request header and body values from with in the lambda code. If the request body is in JSON format, it automatically seems to be parsed and

4条回答
  •  甜味超标
    2021-02-13 23:53

    You have to get the information you need in the template mapping and send them back your Lambda function, this is one of the template I used to send information to the Lambda function:

    {
       "params" : "$input.params()",
       "content-type-value" : "$input.params().header.get('Content-Type')",
       "body" : "$input.json('$')",
       "request-id": "$context.requestId",
       "method": "$context.httpMethod",
       "resource": "$context.resourcePath",
       "id": "$input.params('id')" //This is a path parameter in my case
    }
    

    You can do the same, or you can access params.path.id (again in my case). Here is the link to the documentation.

    Cheers,

提交回复
热议问题