为清楚起见,这发生在Node 6.10 AWS Lambda函数中。
错误:
module initialization error: Error
at Object.Service (/var/task/node_modules/aws-sdk/lib/service.js:24:28)
at Object.features.constructor [as DynamoDB] (/var/task/node_modules/aws-sdk/lib/util.js:602:24)
at Object.<anonymous> (/var/task/web.js:4:22)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
模块的初始化:
const aws = require('aws-sdk');
this.dynamoDb = new aws.DynamoDB();
不知道该怎么做;遗漏了一些明显的东西?
答案 0 :(得分:3)
请尝试,
var AWS = require("aws-sdk");
//If you are running in Lambda you don't need below AWS.config section
AWS.config.update({
region: "REGION"
});
var docClient = new AWS.DynamoDB.DocumentClient();
并使用&#39; docClient&#39;访问DynamoDB功能。
例如,
docClient.put(params, function (err, data) {
if (err) {
console.error("Unable to add item. Error JSON:", JSON.stringify(err,null, 2));
} else {
callback(null, "Error while adding data:", JSON.stringify(data, null, 2))
}
});
请查看我在GitHub中创建的示例: - https://github.com/vnathv/DynamoDb-CRUD.git