[英]Put or Get from a DynamoDB from a Lambda using Nodejs
如果我的 put 或 get 調用在我的 index.js 文件之外的文件中,我遇到了一個問題,我無法使用 DynamoDB 執行任何操作。 例如,我的代碼結構是在 MVC 類型的框架中。 下面我的 exports.handler 在我的 index.js 中,它調用控制器文件夾中的 function。 它開始調用,但是當它到達 put 或 get for dynamo 時,它變為空白(控制台日志記錄)。 沒有錯誤,只是停止。 有人遇到過這個嗎? 下面的例子。
索引.js
const locController = require('./controllers/locationsController');
exports.handler = async(event, context) => {
const routeType ='locations';
const GAID = '1234';
switch(routeType) {
case "locations":
response = await locController.getLocations(GAID);
break;
}
/控制器/locationController.js
'use strict';
const AWS = require('aws-sdk');
const documentClient = new AWS.DynamoDB.DocumentClient();
async function getLocations(event, context, callback) {
var params = {
Item : {
"ProfileID": 1234,
"AppID": 1
},
TableName: "Locations"
};
await documentClient.put(params).promise();
}
module.exports = {getLocations};
如果我在 function 中添加 console.log,它表明我正在進入 function,它只是在寫入表。 同樣的 function 本身放在 index.js 中,工作得很好。
有任何想法嗎?
謝謝。
好吧,在我花時間寫完這篇文章之后,我發現我是多么盲目。 我忘了等待看跌期權。
更改 locationController.js 中的 put 行對我很有效。
await documentClient.put(params).promise();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.