@@ -12,6 +12,7 @@ var Uploader = require('s3-streaming-upload').Uploader;
1212var ReadableStream = require ( './readable-stream' ) ;
1313
1414function DynamoBackup ( options ) {
15+ var params = { } ;
1516 options = options || { } ;
1617 this . excludedTables = options . excludedTables || [ ] ;
1718 this . includedTables = options . includedTables ;
@@ -21,21 +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- // 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- } ) ;
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 ;
3836 }
37+
38+ AWS . config . update ( params ) ;
3939}
4040
4141util . inherits ( DynamoBackup , events . EventEmitter ) ;
@@ -54,21 +54,21 @@ DynamoBackup.prototype.backupTable = function (tableName, backupPath, callback)
5454 backupPath = self . _getBackupPath ( ) ;
5555 }
5656
57- var uploaderParams = {
58- bucket : self . bucket ,
59- objectName : path . join ( backupPath , tableName + '.json' ) ,
60- stream : stream ,
61- debug : self . debug
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 ;
6264 }
6365
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- }
66+ params . bucket = self . bucket ;
67+ params . objectName = path . join ( backupPath , tableName + '.json' ) ;
68+ params . stream = stream ;
69+ params . debug = self . debug ;
7070
71- var upload = new Uploader ( uploaderParams ) ;
71+ var upload = new Uploader ( params ) ;
7272
7373 var startTime = moment . utc ( ) ;
7474 self . emit ( 'start-backup' , tableName , startTime ) ;
0 commit comments