【发布时间】:2021-11-23 23:59:38
【问题描述】:
在 AWS Lambda 代码中,如何获取来自 AWS Gateway API 的 HTTP 请求的 HTTP 方法(例如 GET、POST...)?
我从documentation 了解到 context.httpMethod 是解决方案。
但是,我无法让它工作。
例如,当我尝试添加以下 3 行时:
if (context.httpMethod) {
console.log('HTTP method:', context.httpMethod)
}
进入“microservice-http-endpoint”蓝图的AWS示例代码如下:
exports.handler = function(event, context) {
if (context.httpMethod) {
console.log('HTTP method:', context.httpMethod)
}
console.log('Received event:', JSON.stringify(event, null, 2));
// For clarity, I have removed the remaining part of the sample
// provided by AWS, which works well, for instance when triggered
// with Postman through the API Gateway as an intermediary.
};
我在日志中从来没有任何内容,因为 httpMethod 始终为空。
【问题讨论】:
标签: amazon-web-services aws-lambda aws-api-gateway http-method