Last active
July 20, 2020 00:33
-
-
Save aichholzer/8e69db74ccf03e4964246f7169d7424f to your computer and use it in GitHub Desktop.
Copy data from one DynamoDB table to another.
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
#!/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