Not loading creds from Shared Credentials File
I am using Windows 10 and Windows Subsystem for Linux (WSL). In order to keep my AWS credentials centralized, I have the AWS_CONFIG_FILE and AWS_SHARED_CREDENTIALS_FILE environment variables in Windows set to the location of ~/.aws/config and ~/.aws/credentials in the Linux file system. I have also set AWS_PROFILE to the profile I would like to use.
When I run 'aws configure list' from cmd, it retrieves them just as I would expect. It gives the same output as when I run the command in the Linux subsystem except that the location of config-file is
\Users\Jake\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\jaisrael.aws\config
Rather than
~/.aws/config
The keys it gets are correct. When I check AWS.config.credentials from within a nodejs script however, it comes up as 'null'. I expected it to load credentials from the config and credentials files just as the CLI does.
Hello @jaisrael1
Thanks for reporting this issue.
Is AWS_PROFILE being properly loaded in the nodejs script?
To make sure I'm understanding this fully, which command is giving you these paths?
\Users\Jake\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\jaisrael.aws\config
All 3 environment variables are being properly loaded in the script.
When I type 'aws configure list' in cmd, it prints:
Name Value Type Location ---- ----- ---- -------- profile MFAProfile manual --profile access_key [MYKEY] shared-credentials-file secret_key [MYSECRET] shared-credentials-file region us-east-1 config-file \Users\Jake\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\jaisrael\.aws\config
So that path is the location of the config file that the region is being loaded from. It is stored in the AWS_CONFIG_FILE environment variable.
I found a workaround, I can manually set 'AWS.config.credentials = new AWS.SharedIniFileCredentials({ filename: process.env.AWS_SHARED_CREDENTIALS_FILE});'
As long as I put 'const S3 = new AWS.S3()' after the above line, everything works.
So because I can load the creds from the shared credentials file manually and everything appears to work, it looks like it's just not doing this automatically.
@jaisrael1
Have you set AWS_SDK_LOAD_CONFIG?
That needs to be set for the shared credentials file to be loaded.
See this PR for details: https://github.com/aws/aws-sdk-js/pull/1391#issue-109380362 with additional context here: https://github.com/aws/aws-sdk-js/issues/2197#issuecomment-412942928
That fixed the problem, many thanks!
You're welcome! Closing this issue.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.