0

I have a IAM role and I want to configure my AWS SDK in the Node.js application.

I did try below code:

const AWS = require('aws-sdk');
const sts = new AWS.STS({ region: 'us-east-1' });

const timestamp = (new Date()).getTime();
const params = {
  RoleArn: 'my-iam-role-anr',
  RoleSessionName: `test-session-${timestamp}`,
  ExternalId: 'test-id',
  DurationSeconds: 3600,
};

sts.assumeRole(params, (err, data) => {
   if (err) {
     console.log('Error: ', err);
   } else {
     console.log('Done: ');
     AWS.config.update({
       accessKeyId: data.Credentials.AccessKeyId,
       secretAccessKey: data.Credentials.SecretAccessKey,
       sessionToken: data.Credentials.SessionToken,
     });
   }
});

When I run above code, getting below error:

message: 'Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1',
errno: -113,
code: 'CredentialsError',

How do I get the AWS credentials based on IAM role, and configure the SDK?
Also I want to have AWS SDK configured at one place so that every were I use the SDK I don't need to configure again in the Node.js app.

User7723337
  • 11,857
  • 27
  • 101
  • 182

0 Answers0