I have created an assumed role which has the access of dynamoDB
of other account, and I am getting the assume role credential using AWS
STS
.
var sts = new AWS.STS({apiVersion: '2011-06-15', region:'us-east-1', endpoint: 'https://sts.amazonaws.com'});
console.log("Before calling the assume role");
sts.assumeRole({
DurationSeconds: 3600,
RoleArn: 'arn:aws:iam::123456789012:role/crossAccount',
RoleSessionName: 'awssdk'
}, function(err, data) {
if (err) {
// an error occurred
console.log('Cannot assume role');
console.log(err, err.stack);
} else {
// successful response
console.log('Role assumed');
// Query function
var dynamodb = new AWS.DynamoDB({apiVersion: '2012-08-10', credentials: data, region: 'eu-west-1'});
console.log("dynamo db " + JSON.stringify(dynamodb));
var params = {
Key: {
"Tid": {
S: "123"
},
},
TableName: "MYTable"
};
dynamodb.getItem(params, function(err, data) {
if (err) { console.log(err, err.stack); console.log("failed"); }// an error occurred
else { console.log(data); console.log("success"); } // successful response
});
Following is the exact error :
{ CredentialsError: Missing credentials in config at credError (/var/task/node_modules/aws-sdk/lib/config.js:317:40) at getStaticCredentials (/var/task/node_modules/aws-sdk/lib/config.js:338:15) at Config.getCredentials
Thanks