Created
August 28, 2018 19:28
-
-
Save seansullivan/9f232fe16798ad29a3479464fe1b1f57 to your computer and use it in GitHub Desktop.
Load Local Dynamo from CloudFormation Template
This file contains hidden or 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 AWS = require('aws-sdk'); | |
const _ = require('lodash'); | |
const dynamoEndpoint = 'http://localhost:8000'; | |
console.log(`Establishing connection to local dynamo with endpoint: ${dynamoEndpoint}`); | |
const dynamoDBClient = new AWS.DynamoDB({ | |
endpoint: dynamoEndpoint | |
}); | |
const { Resources: cloudFormationResources } = require('cf.json'); | |
_(cloudFormationResources) | |
.pickBy(({ Type: type }) => type === 'AWS::DynamoDB::Table') | |
.reduce(async (previousPromise, { Properties: properties, Properties: { TableName: tableName } }, ruleName) => { | |
const collection = await previousPromise; | |
console.log(`Creating dynamo resource ${ruleName} with name ${tableName}`); | |
try { | |
collection.successes.push(await dynamoDBClient.createTable(properties).promise()); | |
} catch(e) { | |
collection.errors.push(e); | |
} | |
return collection; | |
}, Promise.resolve({successes: [], errors: []})) | |
.then((results) => console.log(results)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment