Skip to content

Instantly share code, notes, and snippets.

@ahmednuaman
Created May 17, 2017 18:42
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 ahmednuaman/9f60730b5af501dfc44fb4e4484bc774 to your computer and use it in GitHub Desktop.
Save ahmednuaman/9f60730b5af501dfc44fb4e4484bc774 to your computer and use it in GitHub Desktop.
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