Skip to content

Instantly share code, notes, and snippets.

@aichholzer
Last active July 20, 2020 00:33
Show Gist options
  • Save aichholzer/8e69db74ccf03e4964246f7169d7424f to your computer and use it in GitHub Desktop.
Save aichholzer/8e69db74ccf03e4964246f7169d7424f to your computer and use it in GitHub Desktop.
Copy data from one DynamoDB table to another.
#!/usr/bin/env node
/* eslint no-console: 0 */
const AWS = require('aws-sdk');
AWS.config.update({ region: 'ap-southeast-2' });
const db = new AWS.DynamoDB.DocumentClient();
const [, , from, to] = [...process.argv];
if (!from || !to) {
console.error('\n 💥 The "from" and "to" arguments are required.');
process.exit(1);
}
db.scan({ TableName: from })
.promise()
.then((data) => Promise.all(data.Items.map((Item) => db.put({ TableName: to, Item }).promise())))
.then(() => console.log('\n ✔ Done'))
.catch((error) => console.log(`\n 💥 ${error.message}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment