Skip to content

Instantly share code, notes, and snippets.

@basyusuf
Created January 8, 2021 08:22
Show Gist options
  • Save basyusuf/320796484d69c6947393ceab1259dc95 to your computer and use it in GitHub Desktop.
Save basyusuf/320796484d69c6947393ceab1259dc95 to your computer and use it in GitHub Desktop.
Export all DynamoDB items
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