Skip to content Skip to sidebar Skip to footer

Why Do I Need To Hardcode Credentials To Connect To Aws Using The Javascript Sdk?

I've asked this other question here that leads me to believe, by default, the JavaScript AWS SDK looks for credentials in a number of places in your environment without you having

Solution 1:

So after an investigation it seems that this (i.e. the failure on your second snippet) is because you don't have the [default] profile in your .aws/credentials file. Which is a special profile. I assume that the client uses empty strings (or nulls or something) when he can't find it. Which I find amusing to be honest (should throw an exception).

Anyway, to fix that either rename the profile you have to [default] or setup a different profile in your code. Here's the relevant docs:

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/loading-node-credentials-shared.html

I recommend using the AWS_PROFILE environment variable. Will make your code more portable.

Solution 2:

If you're using an IAM role, you don't need to explicitly supply any credentials, null or otherwise:

const AWS = require('aws-sdk');
const athena = new AWS.Athena();
constparams = { ... };
const rc = await athena.startQueryExecution(params).promise();

In fact, this works with credentials supplied via local environment variables or in a credentials/config file too. There's a chain of credentials providers that the SDK will try, one by one.

Post a Comment for "Why Do I Need To Hardcode Credentials To Connect To Aws Using The Javascript Sdk?"