Skip to content

Instantly share code, notes, and snippets.

@seansullivan
Created August 28, 2018 19:28
Show Gist options
  • Save seansullivan/9f232fe16798ad29a3479464fe1b1f57 to your computer and use it in GitHub Desktop.
Save seansullivan/9f232fe16798ad29a3479464fe1b1f57 to your computer and use it in GitHub Desktop.
Load Local Dynamo from CloudFormation Template
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