dynamodb-backup-restore
Advanced tools
Comparing version 0.3.1 to 0.4.0
@@ -6,4 +6,4 @@ { | ||
"dependencies": { | ||
"dynamodb-backup-restore": "0.3.1" | ||
"dynamodb-backup-restore": "0.4.0" | ||
} | ||
} |
@@ -16,19 +16,28 @@ 'use strict'; | ||
fromDbStream(records) { | ||
let allRecords = records.reduce((allRecords, action) => { | ||
const addDataForEvents = ['INSERT', 'MODIFY']; | ||
return records.reduce((allRecords, action) => allRecords.then(allRecords => { | ||
let id = JSON.stringify(action.dynamodb.Keys); | ||
allRecords[id] = allRecords[id] || []; | ||
let change = { | ||
keys: id, | ||
data: JSON.stringify(action.dynamodb.NewImage), | ||
event: action.eventName | ||
}; | ||
allRecords[id].push(change); | ||
return allRecords; | ||
}, {}); | ||
let promises = []; | ||
Object.keys(allRecords).forEach(key => { | ||
promises.push(this.dbRecord.backup(allRecords[key], true)); | ||
}); | ||
return Promise.all(promises) | ||
let pdata = Promise.resolve({}); | ||
if (action.dynamodb.NewImage) { | ||
pdata = Promise.resolve(action.dynamodb.NewImage); | ||
} else if (addDataForEvents.includes(action.eventName)) { | ||
try { | ||
pdata = this.dbInstanceData.getItem(action.dynamodb.Keys); | ||
} catch (e) { | ||
return allRecords; | ||
} | ||
} | ||
return pdata.then(data => { | ||
let change = { | ||
keys: id, | ||
data: JSON.stringify(data), | ||
event: action.eventName | ||
}; | ||
allRecords[id].push(change); | ||
return allRecords; | ||
}); | ||
}), Promise.resolve({})) | ||
.then(allRecords => Promise.all(Object.keys(allRecords).map(key => this.dbRecord.backup(allRecords[key], true)))) | ||
.catch(err => { | ||
@@ -35,0 +44,0 @@ throw err; |
@@ -25,2 +25,18 @@ 'use strict'; | ||
getItem(Key) { | ||
let dynamodb = new AWS.DynamoDB({ region: this.DbRegion }); | ||
let params = { | ||
Key, | ||
TableName: this.DbTable, | ||
ConsistentRead: true | ||
}; | ||
return dynamodb.getItem(params).promise() | ||
.then(data => { | ||
if (data && data.Item) { | ||
return data.Item; | ||
} | ||
return {} | ||
}); | ||
} | ||
getTableKeys() { | ||
@@ -27,0 +43,0 @@ return new Promise((resolve, reject) => { |
{ | ||
"name": "dynamodb-backup-restore", | ||
"version": "0.3.1", | ||
"version": "0.4.0", | ||
"description": "NPM package for Backup and Restore AWS DynamoDB", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/shevchenkos/DynamoDbBackUp", |
@@ -73,2 +73,7 @@ # dynamodb-backup-restore | ||
### AWS Lambda based incremental backup | ||
The DynamoDB Stream StreamViewType needs to be one of `NEW_IMAGE`, `NEW_AND_OLD_IMAGES`, or `KEYS_ONLY`. | ||
Note that [DynamoDB Streams does not support encryption at rest](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/encryption-before-you-start.html). | ||
```javascript | ||
@@ -83,5 +88,8 @@ const Backup = require('dynamodb-backup-restore').Backup; | ||
let config = { | ||
S3Bucket: 'STRING_VALUE', /* required */ | ||
S3Region: 'STRING_VALUE', /* required */ | ||
S3Prefix: 'STRING_VALUE' /* optional */ | ||
S3Bucket: 'STRING_VALUE', /* required */ | ||
S3Region: 'STRING_VALUE', /* required */ | ||
S3Encryption: 'STRING_VALUE', /* optional */ | ||
S3Prefix: 'STRING_VALUE', /* optional */ | ||
DbTable: 'STRING_VALUE', /* required if stream is KEYS_ONLY, ignored otherwise */ | ||
DbRegion: 'STRING_VALUE', /* required if stream is KEYS_ONLY, ignored otherwise */ | ||
}; | ||
@@ -88,0 +96,0 @@ let backup = new Backup(config); |
1657
207
66906
19