Jevy Wang's Blog

Parse URL params using API Gateway and lambda

Lambda script

Lambda could collect POST boday and url params using event . For POST body, params could be extracted directly like event['param1'].
As of September 2017, you no longer have to configure mappings to access the request body.
All you need to do is check, “Use Lambda Proxy integration”, under Integration Request, under the resource of AWS API Gateway.

You’ll then be able to access query parameters, path parameters and headers like so

1
2
3
4
event['pathParameters']['param1']
event["queryStringParameters"]['queryparam1']
event['requestContext']['identity']['userAgent']
event['requestContext']['identity']['sourceIP']

For proxied API, the hander function should return the reponse in following format:

1
2
3
4
5
6
{
"isBase64Encoded": true|false,
"statusCode": httpStatusCode,
"headers": { "headerName": "headerValue", ... },
"body": "..."
}

Usually, when you see Malformed Lambda proxy response, it means your response from your Lambda function doesn’t match the format API Gateway is expecting.


专题:

本文发表于 2020-03-12,最后修改于 2020-03-13。

本站永久域名jevy.wang,也可搜索「 Jevy Wang's Blog 」找到我。

期待关注我的 知乎专栏 ,查看最近的文章和动态。


上一篇 « Add an image layer to react mapbox gl 下一篇 » IP Camera BAT 310 Hacking

赞赏支持

请我吃胡萝卜 =^_^=

i ali

支付宝

i wechat

微信

推荐阅读

Big Image