簡體   English   中英

Lambda 不在 DynamoDB 中創建數據

[英]Lambda doesn't create data in DynamoDB

  1. 我收到代碼響應 200 成功

  2. 但 null json 消息 Postman

  3. 數據不是在 DynamoDB 中創建的。 這是我的 lambda:

     exports.handler = async (event, context, callback) => { const id = replaceAll(event.queryStringParameters.authorId, " ", "-").toLowerCase(); const params = { Item: { id: { S: id }, title: { S: event.queryStringParameters.title }, watchHref: { S: event.queryStringParameters.watchHref }, authorId: { S: event.queryStringParameters.authorId }, length: { S: event.queryStringParameters.length }, category: { S: event.queryStringParameters.category } }, TableName: "todos" }; // console.log("@@@@@@@@@@@ ID " + params.Item.id.S + ""); // console.log("@@@@@@@@@@@ Title " + params.Item.title.S + ""); // console.log("@@@@@@@@@@@ Title " + params.Item.watchHref.S + ""); // console.log("@@@@@@@@@@@ Title " + params.Item.authorId.S + ""); // console.log("@@@@@@@@@@@ Title " + params.Item.length.S + ""); // console.log("@@@@@@@@@@@ Title " + params.Item.category.S + ""); dynamodb.putItem(params, function (err, data) { console.log("@@@@@@@@@@@ ID " + params.Item.id.S + ""); if (err) { console.log("@@@@@@@@@@@ ERROR" + err); callback(err); } else { console.log("@@@@@@@@@@ INSIDE ELSE"); callback(null, { id: params.Item.id.S, title: params.Item.title.S, watchHref: params.Item.watchHref.S, authorId: params.Item.authorId.S, length: params.Item.length.S, category: params.Item.category.S }); } }); };

我究竟做錯了什么? 我遵循與文檔相同的原則。

作為參考,我正在使用 HTTP API 網關代理集成,這是我的表格:

在此處輸入圖像描述

這可能是因為您正在使用異步function 處理程序,該處理程序在您獲得任何結果之前完成。 克服這個問題的一種方法是使用Promise模式,如aws docs中所示。

或者您可能根本不想使用async處理程序。 在這種情況下,您應該從 function 中刪除async並調整處理程序,如非異步處理程序的文檔所示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM