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
});
});