Created
November 8, 2018 08:26
-
-
Save bsingr/2b44f7ac267fc3270d4b2f4330f44c1f to your computer and use it in GitHub Desktop.
dynamodb-dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {DynamoDB} = require('aws-sdk'); | |
const fs = require('fs') | |
let dynamodb = new DynamoDB({ | |
region: 'eu-central-1', | |
endpoint: 'dynamodb.eu-central-1.amazonaws.com', | |
accessKeyId: 'ACC', | |
secretAccessKey: 'SEC' | |
}); | |
var params = { | |
TableName: "TABLE" | |
}; | |
let client = new DynamoDB.DocumentClient({service: dynamodb}); | |
let allItems = [] | |
client.scan(params, onScan); | |
function onScan(err, data) { | |
if (err) { | |
console.error("Unable to scan the table. Error JSON:", JSON.stringify(err, null, 2)); | |
} else { | |
console.log("Scan succeeded.", data.Items.length); | |
allItems = allItems.concat(data.Items) | |
// continue scanning if we have more items | |
if (typeof data.LastEvaluatedKey != "undefined") { | |
console.log("Scanning for more..."); | |
params.ExclusiveStartKey = data.LastEvaluatedKey; | |
client.scan(params, onScan); | |
} else { | |
console.log("Scanning done", allItems.length) | |
fs.writeFileSync('dump.json', JSON.stringify(allItems), 'utf8') | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment