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