So I'm trying to put records into a DynamoDB table from an AWS lambda function. I've set up the role for the lambda function to have access for the lambda function. However, in all the example code from the dynamo documentation below has no reference to an identifier/arn. Is one not needed, and instead the specific dynamoDB instance to use is inferred from the IAM role that the lambda function uses?
Essentially, my question is how can all the code do is call new AWS.DynamoDB(...) and 'automatically' know the right database to access/modify?
Example code:
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 name and region is all you should need to specify.
Is one not needed, and instead the specific dynamoDB instance to use is inferred from the IAM role that the lambda function uses?
The AWS SDK configuration provides the account and region. Those pieces of information, coupled with the table name, are everything it needs to connect to your table. In this case I believe the IAM role provides the account information, and you have specified the table name. You might also need to specify the region depending on if the table is in the default region or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With