Created
January 8, 2021 08:22
-
-
Save basyusuf/320796484d69c6947393ceab1259dc95 to your computer and use it in GitHub Desktop.
Export all DynamoDB items
This file contains hidden or 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 AWS = require('aws-sdk'); | |
AWS.config.update({region:'eu-central-1'}); | |
const fs = require('fs'); | |
const TABLE_NAME = "YOURTABLENAME"; | |
const docClient = new AWS.DynamoDB.DocumentClient({ | |
"sslEnabled": false, | |
"paramValidation": false, | |
"convertResponseTypes": false, | |
"convertEmptyValues": true | |
}); | |
async function exportDB(){ | |
let params = { | |
TableName: TABLE_NAME | |
}; | |
let result = []; | |
let items; | |
do { | |
items = await docClient.scan(params).promise(); | |
items.Items.forEach((item) => result.push(item)); | |
params.ExclusiveStartKey = items.LastEvaluatedKey; | |
} while(typeof items.LastEvaluatedKey != "undefined"); | |
await fs.writeFileSync("exported_data.json", JSON.stringify(result,null, 4)); | |
console.info("Available count size:", result.length); | |
} | |
exportDB(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment