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

后端 未结 4 1393
忘掉有多难
忘掉有多难 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-14 00:00

    I updated the mapping template I used in the answer to one of the referenced questions to contain the userAgent property.

    {
      "method": "$context.httpMethod",
      "body": $input.json('$'),
      "userAgent": "$context.identity.userAgent",
      "headers": {
        #foreach($param in $input.params().header.keySet())
        "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end
    
        #end
      },
      "queryParams": {
        #foreach($param in $input.params().querystring.keySet())
        "$param": "$util.escapeJavaScript($input.params().querystring.get($param))" #if($foreach.hasNext),#end
    
        #end
      },
      "pathParams": {
        #foreach($param in $input.params().path.keySet())
        "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end
    
        #end
      }  
    }
    

    A detailed explanation of the template is available here: http://kennbrodhagen.net/2015/12/06/how-to-create-a-request-object-for-your-lambda-event-from-api-gateway/

提交回复
热议问题