Question:
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
1 2 3 4 5 6 |
aws.config.update({ region: process.env.AWS_region, accessKeyId: process.env.AWS_ACCESS_KEY_ID, secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY, }); |
and that worked.
any idea why AWS SDK doesn’t load the options automatically?
1 2 3 |
"aws-sdk": "^2.288.0", "dotenv": "^6.0.0", |
Answer:
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.