Skip to content

Instantly share code, notes, and snippets.

@aichholzer
Last active July 20, 2020 00:33
Show Gist options
  • Select an option

  • Save aichholzer/8e69db74ccf03e4964246f7169d7424f to your computer and use it in GitHub Desktop.

Select an option

Save aichholzer/8e69db74ccf03e4964246f7169d7424f to your computer and use it in GitHub Desktop.

Revisions

  1. aichholzer revised this gist Jul 20, 2020. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions copydyn.js
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    #!/usr/bin/env node

    /* eslint no-console: 0 */
    const AWS = require('aws-sdk');
    AWS.config.update({ region: 'ap-southeast-2' });
  2. aichholzer created this gist Jul 20, 2020.
    16 changes: 16 additions & 0 deletions copydyn.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    /* 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}`));