mousavian / dr-dynamo

DynamoDB Disaster Recovery - A tool to backup DynamoDB tables to S3 and restore
MIT License
4 stars 3 forks source link

Bug fix when specifying S3 object params #1

Closed miguelduarte42 closed 7 years ago

miguelduarte42 commented 7 years ago

This fixes a bug which reveals itself when you use the objectParams property. Example:

let backup = new DynamoBackup({
        aws: {
          region: myRegion,
          accessKeyId: myKey,
          secretAccessKey: mySecret,
          objectParams: {
            ServerSideEncryption: 'AES256',
            StorageClass: 'STANDARD_IA'
          }
        },
        includedTables: ['table1','table2],
        readPercentage: .85,
        bucket: myBucket
      });

The objectParam property is copied over to the S3 params object which is handed off to the Uploader (s3-streaming-upload). The problem is that the Uploader appends some other data to the params, such as the Key of the file, and the data spills over to the awsConfig object on DynamoBackup. This happens because Object.assign on line 48 performs a shallow copy, and the original objectParams object is changed.

The symptom is that if you backup several tables simultaneously, they will all share the same Key property, and only 1 .json file will be saved in the bucket.

The solution was to perform a deep copy of the object using JSON.stringify and JSON.parse

I also included documentation on how to use the objectParams property.

mousavian commented 7 years ago

@miguelduarte42 Thank you for your contribution and sorry for delay to merging this, somehow I missed notification. Will publish to npm in few minutes.