Version: 2.4.3
~/.aws/config isn't checked for region information when trying to perform a connection.
To reproduce:
~/.aws/config:
[default]
region=us-east-1
~/.aws/credentials:
[default]
aws_access_key_id = changed
aws_secret_access_key = changed
~/test.js:
var AWS = require('aws-sdk');
// Get a list of kms keys
var kms = new AWS.KMS();
var params = {
Limit: 0,
Marker: 'STRING_VALUE'
};
kms.listKeys(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Also worth noting, if I rm ~/.aws/credentials, put aws_access_key_id and aws_secret_access_key in ~/.aws/config I still get the above error.
Relevant doc on how the AWS cli precedence: http://docs.aws.amazon.com/cli/latest/topic/config-vars.html#id1
Hi @jjshoe
The SDK does not currently support sourcing configuration from ~/.aws/config, as this is intended for the AWS CLI.
These are the supported ways for configuring the region in the AWS SDK for JavaScript:
You update the region in your code using AWS.config.update():
AWS.config.update({region: 'us-east-1'});
Or you can set your environment variable AWS_REGION to the desired region, and this will allow you to keep the region private and not hard-code it in your code.
Or you could also set your configuration, including the region, in a .json file, and then load it by providing the file path to AWS.config.loadFromPath():
AWS.config.loadFromPath('./myConfiguration.json');
Note that using this method will delete and replace your existing configuration with the configuration in your .json file, so you will either need to specify all of your global configuration here or load it first before updating any additional configuration.
Let me know if that resolves the error you're running into!
This is a feature request that we are looking into implementing in the future.
I, too, would like to see reading of the config file in resolving the credential chain. In my case, it's for automatic role assumption (using role_arn, source_profile, mfa_serial, etc.) via the config file. I have a CLI that I wrote with this module, and I would like for users' credentials to resolve however they would with the AWS CLI.
Addressed in #1391.
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.
Most helpful comment
This is a feature request that we are looking into implementing in the future.