Anjana
Anjana

Reputation: 426

Aws Error Could not load credentials from any providers

I have a node service, which creates temporary AWS credentials using sts.assumeRole(params). If I set the accessKeyId,secretAccessKey,region in the environment. Credentials are generated successfully. If I store them in Mongo and read them. I get the following error.

Errors

Error Could not load credentials from any providers

Error region is missing

Code

const params = {
        RoleArn: `arn:aws:iam::${db.awsAccountId}:role/${db.awsRole}`,
        RoleSessionName: `Assumed-${db.awsRole}-Role-${timestamp}`,
        accessKeyId: db.accessId,
        secretAccessKey: db.accessToken,
        region: db.awsRegion,
      };

sts.assumeRole(params, (err, data) => {
    if(err) console.log(err);
    else console.log(data);
});

I don't understand, following the same procedure. Any ideas?

Upvotes: 0

Views: 9718

Answers (1)

stijndepestel
stijndepestel

Reputation: 3554

It looks like you are setting the AWS credentials for the STS service incorrectly. You should have a look at the user guide for the full explanation.

There are multiple ways to set credentials, so pick the one that works best in your situation. When you were using environment variables, they were picked up automatically, but if you're reading them from some other place, you'll have to create a Credentials object and add it to the AWS.config manually.

More info on the Credentials object can be found here and on the AWS.config here.

Upvotes: 0

Related Questions