我的建筑:
integration
我正在尝试检查请求方法来处理操作,基于this回答,它们可以重传
'use strict';
const AWS = require('aws-sdk');
const dynamo = new AWS.DynamoDB.DocumentClient();
exports.handler = async (event) => {
switch (event.httpMethod) {
case 'GET':
break;
default:
throw new Error(`@@@@ Unsupported method "${event.httpMethod}"`);
}
return {
statusCode: 200,
body: JSON.stringify({message: 'Success'})
};
};我在lambda中粘贴了类似的代码,但是它不起作用,我在日志中得到了这个错误:
"errorMessage": "@@@@ Unsupported method \"undefined\"",这个lambda是由我的HTTP触发的,路由有GET方法。
如果我返回事件,我可以看到方法是GET或POST,或者其他什么,请看:

有人知道这是怎么回事吗?
发布于 2021-01-23 03:19:36
HTTP (v2)的输入对象模式()不同于REST (与link不同)。
对于Http,可以从event.requestContext.http.method获得方法。
所以,看起来会是这样。
exports.handler = async (event) => {
console.log('event',event);
switch (event.requestContext.http.method) {
case 'GET':
console.log('This is a GET Method');
break;
default:
throw new Error(`@@@@ Unsupported method "${event.httpMethod}"`);
}
const response = {
statusCode: 200,
body: JSON.stringify('Hello from Lambda!'),
};
return response;
};https://stackoverflow.com/questions/65855161
复制相似问题