[英]DynamoDB.putItem is not saving
此代碼在 Cognito 注冊 postConfirmation 后調用,dynamo.putItem 不工作且未登錄到 Cloudwatch。 我嘗試添加 CloudTrail 日志,但它們沒有顯示任何內容。
是什么原因 ?
謝謝你的幫助 !
...
module.exports.router = async (event, context) => {
if (process.env.npm_lifecycle_event !== "test") {
console.debug("event", event);
console.debug("context", context);
}
let response = null;
if (event.userPoolId) {
if (event.userPoolId == process.env.COGNITO_POOL) {
try {
if (event.triggerSource == 'PostConfirmation_ConfirmSignUp') {
const now = new Date().toISOString();
var actual = {
userName: event.userName,
created: now,
publicKey: "la mia chiave pubblica",
privateKey: "la mia chiave privata"
};
dynamo.putItem({
ReturnConsumedCapacity: "TOTAL",
TableName: process.env.USERS_TABLE,
Item: converter.marshall(actual)
}, (_err, _data) => {
console.debug("into putItem !!!");
if (_err) {
console.log("error", _err);
} else {
console.log("added", _data);
}
});
} else {
}
} catch (error) {
console.log(error);
}
response = event;
} else {
throw new Error(`Wrong pool event.userPoolId`);
}
} else {
throw new Error(`No pool`);
}
return response;
}
您不是在等待 dynamo.putItem 完成,而是在發出網絡請求之前關閉 Lambda 函數。
由於您已將函數設置為異步,因此您應該在 putItem() 方法上調用 .promise() 以便它返回一個 Promise。 然后,您可以等待承諾,以便在 DynamoDB 調用成功之前 lambda 不會停止。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.