AWS JS SDK doesn’t Loading Credentials from environment variables


I configured .env file to have AWS credentials, it doesn’t work.

in the docs, it is written the config will automatically be loaded from .env file. but it doesn’t.

I tried to add the following

and that worked.

any idea why AWS SDK doesn’t load the options automatically?


Old question, but answering as I had this issue with a test.

This is due to the AWS SDK capturing the credentials when the sdk is first required or imported.

When you run dotenv.config(), it has already completed this and does not re-read the environment variables.

Updating the AWS config yourself sets the values and is a reasonable solution.

Leave a Reply