我正在设置一个 AWS Lambda 函数来连接到我的 DynamoDB。为了访问它,我还设置了一个 API 网关。
当我测试它时,lambda 似乎工作。因此,我认为问题出在 API 网关设置中。
对于 lambda,我配置了以下测试事件:我配置了一个如下所示的测试事件:
{
"httpMethod": "GET"
}
Run Code Online (Sandbox Code Playgroud)
此测试事件给了我以下响应:
Response:
{
"statusCode": "200",
"body": "{\"Items\":[{\"id\":1,\"brand\":\"Test brand\",\"title\":\"Test product\"}],\"Count\":1,\"ScannedCount\":1}",
"headers": {
"Content-Type": "application/json"
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试在 lambda 管理控制台中自动创建 API 网关。重新创建 lambda 和 API 网关。
拉姆达函数:
console.log('Loading function');
const doc = require('dynamodb-doc');
const dynamo = new doc.DynamoDB();
/**
* Demonstrates a simple HTTP endpoint using API Gateway. You have full
* access to the request and response payload, including headers and …Run Code Online (Sandbox Code Playgroud)