Created
March 12, 2020 12:44
-
-
Save coderbyheart/bf87c37f625411a6ccff31ace2f59cb1 to your computer and use it in GitHub Desktop.
copy DynamoDB items to another table
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
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