AWS:如何在 javascript SDK 中指定 dynamodb arn

AWS : How to specify dynamodb arn in javascript SDK

所以我正在尝试从 AWS lambda 函数将记录放入 DynamoDB table。我已经为 lambda 函数设置了角色以访问 lambda 函数。但是,在下面的所有 example code from the dynamo documentation 中都没有引用 identifier/arn。是否不需要,而是根据 lambda 函数使用的 IAM 角色推断要使用的特定 dynamoDB 实例?

本质上,我的问题是所有代码如何调用 new AWS.DynamoDB(...) 和 'automatically' 知道 access/modify 的正确数据库?

示例代码:

var table = new AWS.DynamoDB({apiVersion: '2012-08-10', params: {TableName: 'MY_TABLE'}});
var key = 'UNIQUE_KEY_ID';

// Write the item to the table
var itemParams = {
   Item: {
     id: {S: key}, 
     data: {S: 'data'}
   }
};
table.putItem(itemParams, function() {
    // Read the item from the table
    table.getItem({Key: {id: {S: key}}}, function(err, data) {
    console.log(data.Item); // print the item data
    });
});

Table 名称和区域是您需要指定的全部内容。

Is one not needed, and instead the specific dynamoDB instance to use is inferred from the IAM role that the lambda function uses?

AWS SDK 配置提供账户和区域。这些信息,再加上 table 的名字,就是连接到您的 table 所需的一切。在这种情况下,我相信 IAM 角色提供了帐户信息,并且您指定了 table 名称。您可能还需要根据 table 是否在默认区域中来指定区域。