Skip to content

Add AWS_CREDENTIAL_PROFILES_FILE Environment Variable #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "EnvironmentVariable",
"description": "Add AWS_CREDENTIAL_PROFILES_FILE Environment Variable as defined in the Java AWS_SDK"
}
3 changes: 3 additions & 0 deletions doc-src/guide/node-configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ You may configure credentials for multiple access keys in the same shared
configuration file using *profiles*. This is discussed in the last part of
this section.

You can specify a different location for the shared credentials file
by using the `AWS_CREDENTIAL_PROFILES_FILE` environment variable.

##### Creating the Shared Credentials File

If you do not already have a shared credentials file, you can create one in
Expand Down
10 changes: 6 additions & 4 deletions lib/credentials/shared_ini_file_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ var STS = require('../../clients/sts');

/**
* Represents credentials loaded from shared credentials file
* (defaulting to ~/.aws/credentials).
* (defaulting to ~/.aws/credentials or defined by the
* `AWS_CREDENTIAL_PROFILES_FILE` environment variable).
*
* ## Using the shared credentials file
*
Expand Down Expand Up @@ -39,8 +40,9 @@ AWS.SharedIniFileCredentials = AWS.util.inherit(AWS.Credentials, {
* @param options [map] a set of options
* @option options profile [String] (AWS_PROFILE env var or 'default')
* the name of the profile to load.
* @option options filename [String] ('~/.aws/credentials') the filename
* to use when loading credentials.
* @option options filename [String] ('~/.aws/credentials' or defined by
* AWS_CREDENTIAL_PROFILES_FILE process env var)
* the filename to use when loading credentials.
* @option options disableAssumeRole [Boolean] (false) True to disable
* support for profiles that assume an IAM role. If true, and an assume
* role profile is selected, an error is raised.
Expand All @@ -50,7 +52,7 @@ AWS.SharedIniFileCredentials = AWS.util.inherit(AWS.Credentials, {

options = options || {};

this.filename = options.filename;
this.filename = options.filename || process.env.AWS_CREDENTIAL_PROFILES_FILE;
this.profile = options.profile || process.env.AWS_PROFILE || 'default';
this.disableAssumeRole = !!options.disableAssumeRole;
this.get(function() {});
Expand Down
16 changes: 16 additions & 0 deletions test/credentials.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ if AWS.util.isNode()
describe 'AWS.SharedIniFileCredentials', ->
beforeEach ->
delete process.env.AWS_PROFILE
delete process.env.AWS_CREDENTIAL_PROFILES_FILE
delete process.env.HOME
delete process.env.HOMEPATH
delete process.env.HOMEDRIVE
Expand Down Expand Up @@ -209,6 +210,21 @@ if AWS.util.isNode()
validateCredentials(creds)
expect(AWS.util.readFileSync.calls[0].arguments[0]).to.equal('/home/user/.aws/credentials')

it 'loads credentials from path defined in AWS_CREDENTIAL_PROFILES_FILE', ->
process.env.AWS_CREDENTIAL_PROFILES_FILE = '/path/to/aws/credentials'
mock = '''
[default]
aws_access_key_id = akid
aws_secret_access_key = secret
aws_session_token = session
'''
helpers.spyOn(AWS.util, 'readFileSync').andReturn(mock)

creds = new AWS.SharedIniFileCredentials()
creds.get();
validateCredentials(creds)
expect(AWS.util.readFileSync.calls[0].arguments[0]).to.equal('/path/to/aws/credentials')

it 'loads the default profile if AWS_PROFILE is empty', ->
process.env.AWS_PROFILE = ''
mock = '''
Expand Down