向 APIGatewayProxyRequestEvent 添加 HttpMethod 属性,并设置为请求的 HTTP 方法。在 AWS SAM 的本地启动中,则需在模拟的事件中添加 HttpMethod 属性。
示例代码:
exports.handler = async (event) => {
const { httpMethod } = event;
if (!httpMethod) {
event.httpMethod = 'GET'; // 设置默认 HttpMethod
}
// 其他代码
}