如何在Nodejs中配置AWS dynamoDB区域?

时间:2018-05-25 06:51:08

标签: node.js amazon-web-services amazon-dynamodb

我有以下代码用于向dynamoDB添加项目。我已将该区域设置为ap-south-1,但该项目已添加到us-east-1区域。

AWS.config.update({
    region: "ap-south-1",
    endpoint: "dynamodb.ap-south-1.amazonaws.com"
});

var addDocumentToTable = function (tablename, item, callback) {

    var docClient = new AWS.DynamoDB.DocumentClient();
    var params = {
        TableName: tablename,
        Item: item
    }
    docClient.put(params, function (err, data) {
        retData = { status: true, message: "Successfully inserted", error: null };
        if (err) {
            retData.status = false;
            retData.message = "Failed to insert into DynamoDB";
            retData.error = err;
        }
        callback(err, retData);
    });
}

1 个答案:

答案 0 :(得分:1)

将详细信息添加到DocumentClient已经解决了它。

var docClient = new AWS.DynamoDB.DocumentClient({ region: Config.AWS.AWS_REGION, endpoint: Config.AWS.ENDPOINT });