How to Load config from ~/.aws/config
The answer of sreenivas is correct. It also seems to be the only way to do this without writing a custom function.
I've traced it back in the source code and the the way it loads ~/.aws/config
is similar to this pseudocode:
if process.env.AWS_SDK_LOAD_CONFIG:
return load('~/.aws/credentials').overwrite('~/.aws/config')
else:
return load('~/.aws/credentials')
This also means you can set the environment variable after require('aws-sdk')
, as long as you do it before new SharedIniFileCredentials({..})
or credentials.refresh()
. Beware that credentials.get()
will not work until the sessiontoken has expired.
There is a little bit of magic in how aws-sdk loads the config
either set the env variable
export AWS_SDK_LOAD_CONFIG="true"
or before loading the aws-sdk set
process.env.AWS_SDK_LOAD_CONFIG = true;
Then load the aws module;
var AWS = require('aws-sdk');
You can access the region directly by
AWS.config.region