Skip to content

Commit 6919bd2

Browse files
Merge pull request #23 from markitx/dwkerwin-iam-role-compatibility
IAM role compatibility
2 parents cd6f9d6 + cfedf05 commit 6919bd2

File tree

2 files changed

+29
-18
lines changed

2 files changed

+29
-18
lines changed

lib/dynamo-backup.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var Uploader = require('s3-streaming-upload').Uploader;
1212
var ReadableStream = require('./readable-stream');
1313

1414
function DynamoBackup(options) {
15+
var params = {};
1516
options = options || {};
1617
this.excludedTables = options.excludedTables || [];
1718
this.includedTables = options.includedTables;
@@ -21,16 +22,20 @@ function DynamoBackup(options) {
2122
this.stopOnFailure = options.stopOnFailure || false;
2223
this.base64Binary = options.base64Binary || false;
2324
this.saveDataPipelineFormat = options.saveDataPipelineFormat || false;
24-
this.awsAccessKey = options.awsAccessKey || process.env.AWS_ACCESS_KEY_ID;
25-
this.awsSecretKey = options.awsSecretKey || process.env.AWS_SECRET_ACCESS_KEY;
26-
this.awsRegion = options.awsRegion || process.env.AWS_DEFAULT_REGION || 'us-east-1';
25+
this.awsAccessKey = options.awsAccessKey;
26+
this.awsSecretKey = options.awsSecretKey;
27+
this.awsRegion = options.awsRegion;
2728
this.debug = Boolean(options.debug);
2829

29-
AWS.config.update({
30-
accessKeyId: this.awsAccessKey,
31-
secretAccessKey: this.secretAccessKey,
32-
region: this.awsRegion
33-
});
30+
if (this.awsRegion) {
31+
params.region = this.awsRegion;
32+
}
33+
if (this.awsAccessKey && this.awsSecretKey) {
34+
params.accessKeyId = this.awsAccessKey;
35+
params.secretAccessKey = this.awsSecretKey;
36+
}
37+
38+
AWS.config.update(params);
3439
}
3540

3641
util.inherits(DynamoBackup, events.EventEmitter);
@@ -49,15 +54,21 @@ DynamoBackup.prototype.backupTable = function (tableName, backupPath, callback)
4954
backupPath = self._getBackupPath();
5055
}
5156

52-
var upload = new Uploader({
53-
accessKey: self.awsAccessKey,
54-
secretKey: self.awsSecretKey,
55-
region: self.awsRegion,
56-
bucket: self.bucket,
57-
objectName: path.join(backupPath, tableName + '.json'),
58-
stream: stream,
59-
debug: self.debug
60-
});
57+
var params = {};
58+
if (self.awsRegion) {
59+
params.region = self.awsRegion;
60+
}
61+
if (self.awsAccessKey && self.awsSecretKey) {
62+
params.accessKey = self.awsAccessKey;
63+
params.secretKey = self.awsSecretKey;
64+
}
65+
66+
params.bucket = self.bucket;
67+
params.objectName = path.join(backupPath, tableName + '.json');
68+
params.stream = stream;
69+
params.debug = self.debug;
70+
71+
var upload = new Uploader(params);
6172

6273
var startTime = moment.utc();
6374
self.emit('start-backup', tableName, startTime);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dynamo-backup-to-s3",
3-
"version": "0.4.1",
3+
"version": "0.4.2",
44
"author": "Dylan Lingelbach (https://github.com/dylanlingelbach)",
55
"license": "MIT",
66
"repository": {

0 commit comments

Comments
 (0)