Skip to content

Commit 6f65990

Browse files
committed
fixed access issue from lambda via IAM role temp creds
1 parent cf0d955 commit 6f65990

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

lib/dynamo-backup.js

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@ function DynamoBackup(options) {
2626
this.awsRegion = options.awsRegion || process.env.AWS_DEFAULT_REGION || 'us-east-1';
2727
this.debug = Boolean(options.debug);
2828

29-
AWS.config.update({
30-
accessKeyId: this.awsAccessKey,
31-
secretAccessKey: this.secretAccessKey,
32-
region: this.awsRegion
33-
});
29+
// ensure that temporary credentials from IAM role don't get
30+
// passed in as user access key without session token
31+
if (this.awsAccessKey !== undefined &&
32+
this.awsAccessKey.lastIndexOf('AKIA', 0) === 0) {
33+
AWS.config.update({
34+
accessKeyId: this.awsAccessKey,
35+
secretAccessKey: this.secretAccessKey,
36+
region: this.awsRegion
37+
});
38+
}
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,
57+
var uploaderParams = {
5658
bucket: self.bucket,
5759
objectName: path.join(backupPath, tableName + '.json'),
5860
stream: stream,
5961
debug: self.debug
60-
});
62+
}
63+
64+
if (self.awsAccessKey !== undefined &&
65+
self.awsAccessKey.lastIndexOf('AKIA', 0) === 0) {
66+
uploaderParams.accessKey = self.awsAccessKey;
67+
uploaderParams.secretKey = self.awsSecretKey;
68+
uploaderParams.region = self.awsRegion;
69+
}
70+
71+
var upload = new Uploader(uploaderParams);
6172

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

0 commit comments

Comments
 (0)