Fine-grained Access with AssumeRole
const AWS = require('aws-sdk');
const sts = new AWS.STS();
sts.assumeRole({
RoleArn: '<role arn>',
RoleSessionName: 'MySession'
}, (err, data) => {
if (err) { // an error occurred
console.log('Cannot assume role');
console.log(err, err.stack);
} else { // successful response
// This is important as AssumeRole will not automatically update the existing Lambda role
AWS.config.update({
accessKeyId: data.Credentials.AccessKeyId,
secretAccessKey: data.Credentials.SecretAccessKey,
sessionToken: data.Credentials.SessionToken
});
}
});Last updated