Skip to content

Commit

Permalink
Fix conflict with Global AWS.config
Browse files Browse the repository at this point in the history
  • Loading branch information
marcogadget committed Oct 2, 2017
1 parent 6dae9ba commit f6afe30
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ module.exports = (region = 'eu-central-1', config) => {
var dynamoDB, configObj;

if (typeof config === 'string') {
configObj = Object.assign(JSON.parse(require('fs').readFileSync(config, 'utf8')), { region: region } );
configObj = Object.assign(JSON.parse(require('fs').readFileSync(config, 'utf8')) );
} else if (typeof config === 'object') {
configObj = Object.assign(config, { region: region })
} else {
// This will force using STS as fallback credentials provider
if (!configObj) configObj = new AWS.ECSCredentials();
if (!configObj) configObj = new AWS.SharedIniFileCredentials();
if (!configObj) configObj = new AWS.EnvironmentCredentials('AWS');
configObj = config
}

// This will force using STS as fallback credentials provider
if (!Object.keys(configObj).length) configObj = new AWS.ECSCredentials();
// if (!Object.keys(configObj).length) configObj = new AWS.SharedIniFileCredentials();
// if (!Object.keys(configObj).length) configObj = new AWS.EnvironmentCredentials('AWS');

// Merge the region into config object
if (region) {
configObj = Object.assign(configObj, { region: region })
}

dynamoDB = new AWS.DynamoDB( configObj );
Expand Down

0 comments on commit f6afe30

Please sign in to comment.