Skip to content

Instantly share code, notes, and snippets.

@coderbyheart
Created March 12, 2020 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderbyheart/bf87c37f625411a6ccff31ace2f59cb1 to your computer and use it in GitHub Desktop.
Save coderbyheart/bf87c37f625411a6ccff31ace2f59cb1 to your computer and use it in GitHub Desktop.
copy DynamoDB items to another table
import AWS from 'aws-sdk'
const db = new AWS.DynamoDB();
const oldTable = 'bifravst-cellGeolocationdeviceCellGeoLocations9F25FBED-1VK9FPSS5GX3G'
const newTable = 'bifravst-cellGeolocationdeviceCellGeoLocation757F8D27-1K6Z9IBMWMV2K'
const refill = (ExclusiveStartKey) => db.scan({
TableName: oldTable,
Limit: 100,
ExclusiveStartKey
}).promise()
.then(async ({ LastEvaluatedKey, Items }) => {
console.dir(Items, { depth: 10 })
await Promise.all(Items.map(Item => db.putItem({
Item,
TableName: newTable
}).promise()))
if (LastEvaluatedKey) return refill(LastEvaluatedKey)
})
refill()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment