Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Serverless-dynamodb-local migration to AWS script
const { basename, join } = require('path')
const { DynamoDB } = require('aws-sdk')
const { readFileSync } = require('fs')
const glob = require('glob')
const doc = new DynamoDB.DocumentClient({
region: 'eu-west-2'
})
glob(join(process.cwd(), 'seed/db/*.json'), (error, files) => {
if (error) {
console.log(error)
}
const payload = {
RequestItems: files.reduce((result, file) => {
const items = JSON.parse(readFileSync(file))
result[basename(file, '.json')] = items.map((Item) => ({
PutRequest: { Item }
}))
return result
}, {})
}
doc.batchWrite(payload, (error, result) => console.log(error, result))
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment