Skip to content

Commit f9b1c36

Browse files
authored
fix: missing credentials file with config file (#3684)
1 parent 6c89bc5 commit f9b1c36

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Credentials",
4+
"description": "Do not require credentials file when loading region from config."
5+
}

lib/node_loader.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ AWS.util.update(AWS.Config.prototype.keys, {
9898
];
9999
var iniLoader = AWS.util.iniLoader;
100100
while (!region && toCheck.length) {
101-
var configFile = iniLoader.loadFrom(toCheck.shift());
101+
var configFile = {};
102+
var fileInfo = toCheck.shift();
103+
try {
104+
configFile = iniLoader.loadFrom(fileInfo);
105+
} catch (err) {
106+
if (fileInfo.isConfig) throw err;
107+
}
102108
var profile = configFile[env.AWS_PROFILE || AWS.util.defaultProfile];
103109
region = profile && profile.region;
104110
}

test/config.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ describe('AWS.Config', function() {
150150
var config = new AWS.Config();
151151
expect(config.region).to.equal('us-east-1');
152152
});
153+
154+
it('non-existent credentials file returns empty', function() {
155+
process.env.AWS_SDK_LOAD_CONFIG = '1';
156+
var mock = '[default]\nregion = us-west-2';
157+
helpers.spyOn(AWS.util, 'readFileSync').andCallFake(function(path) {
158+
if (path.match(/[\/\\]home[\/\\]user[\/\\].aws[\/\\]config/)) {
159+
return mock;
160+
} else {
161+
throw new Error('File does not exist!');
162+
}
163+
});
164+
var config = new AWS.Config();
165+
expect(config.region).to.equal('us-west-2');
166+
});
153167
});
154168
}
155169

0 commit comments

Comments
 (0)