javascript - DyanmoDB getItem 未在 Async Lambda 中提供任何响应
问题描述
我一直在尝试在异步 Lambda 函数中向 dynamo DB 发出 getItem 请求,但我根本没有收到任何响应。任何故障排除或帮助将不胜感激。
一般来说,我正在尝试使用 AWS SDK getItem 向 dynamodb 表发出请求,但是,当我运行我的代码时,等待 ddb.getItem 函数没有响应
所以我有点不知道是什么原因造成的。
// Load AWS SDK
const AWS = require("aws-sdk");
// Set the region
AWS.config.update({ region: "us-east-1" });
// Create the DyanmoDB service object
const ddb = new AWS.DynamoDB({ apiVersion: "2012-08-10" });
const handler = async (
event,
context,
callback,
test = false,
testObjFunc = {
test: () => {
Error("Testing enabled");
}
}
) => {
const response = {
isBase64Encoded: false,
statusCode: 200,
headers: { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*" },
multiValueHeaders: {},
body: JSON.stringify({ responseBody })
};
try {
// Parameters for DynamodDB getItem call
const dbParams = {
TableName: "Table_Name",
Key: {
personID: { S: "value" }
},
ProjectionExpression: "value_to_return"
};
// DynamoDB call to check for item
const results = await ddb.getItem(dbParams).promise();
console.log("success");
console.log(results);
} catch (error) {
response.statusCode = 500;
}
return response;
};
module.exports.handler = handler;
解决方案
您已将 getitem 调用放入 try 块中,因为您没有收到任何响应意味着 try 块中出现问题。
推荐阅读
- java - Java 三角递归
- nativescript - Nativescript RadDataForm MultilineText 无法在 Android 上运行
- ios - 在自定义 UIButton 子类上添加带圆角的阴影层
- sql-server - SQL Server 复制粘贴无分栏符
- html - 应用程序缓存 - HTML 5
- python - 从 Python 中的字符列表创建句子(R 代码翻译)
- java - 我们正在做“组”来创造摇滚、纸、剪刀。我们用 1 块石头,2 块纸,3 块剪刀
- perl - AppleScript 替换多个文件中的文本
- node.js - 如何查看实际用于我的应用程序包的软件包列表?
- reactjs - 无法在“历史”上执行“pushState”:函数 addComment() ... 无法克隆