Skip to content

Commit 7f04535

Browse files
authored
Merge pull request #1 from pushpay/aws_configuration
use default keys and region if not provided
2 parents 77ca065 + ccfaeb6 commit 7f04535

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

lib/dynamo-restore.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,28 @@ var readline = require('readline');
1414
var DYNAMO_CHUNK_SIZE = 25;
1515

1616
function DynamoRestore(options) {
17+
var params = {};
1718
options = options || {};
1819
options.concurrency = options.concurrency || 200;
1920
options.minConcurrency = 1;
2021
options.maxConcurrency = options.concurrency;
2122
options.readcapacity = options.readcapacity || 5;
2223
options.writecapacity = options.writecapacity || 0;
2324
options.stopOnFailure = options.stopOnFailure || false;
24-
options.awsKey = options.awsKey || process.env.AWS_ACCESS_KEY_ID;
25-
options.awsSecret = options.awsSecret || process.env.AWS_SECRET_ACCESS_KEY;
26-
options.awsRegion = options.awsRegion || process.env.AWS_DEFAULT_REGION || 'ap-southeast-2';
2725

28-
AWS.config.update({
29-
accessKeyId: options.awsKey,
30-
secretAccessKey: options.awsSecret,
31-
region: options.awsRegion
32-
});
26+
if (options.awsRegion) {
27+
params.region = options.awsRegion;
28+
}
29+
else if (!process.env.AWS_REGION) {
30+
params.region = process.env.AWS_DEFAULT_REGION || 'ap-southeast-2';
31+
}
32+
33+
if (options.awsKey && options.awsSecret) {
34+
params.accessKeyhId = options.awsKey;
35+
params.secretAccessKey = options.awsSecret;
36+
}
37+
38+
AWS.config.update(params);
3339

3440
this.options = options;
3541
this.dynamodb = new AWS.DynamoDB();
@@ -360,4 +366,4 @@ DynamoRestore.prototype._finishBatches = function() {
360366
setTimeout(this._finishBatches.bind(this), 200);
361367
};
362368

363-
module.exports = DynamoRestore;
369+
module.exports = DynamoRestore;

0 commit comments

Comments
 (0)