Skip to content

Instantly share code, notes, and snippets.

@sethkrasnianski
Created March 14, 2019 20:04
Show Gist options
  • Save sethkrasnianski/b15cdfb6d10175b305b05fcf80102d8a to your computer and use it in GitHub Desktop.
Save sethkrasnianski/b15cdfb6d10175b305b05fcf80102d8a to your computer and use it in GitHub Desktop.
Batched DynamoDB Transactions - WIP
const seedTransaction = async (tableMap, data) => {
// Each key in data contains its type in parenthesis
// We must remove them before we can properly map over them
const formattedData = data.map(d => {
const keys = Object.keys(d).map(k => k.substring(0, k.indexOf(' ')));
const values = Object.values(d);
return keys.reduce((acc, k, i) => {
acc[k] = values[i];
return acc;
}, {});
});
// Dynamo limits transaction writes to 10 records total
const chunkedData = chunk(formattedData, 10);
const params = {
TransactItems: [
// ...
]
};
// dynamodb.transactWriteItems(params, function(err, data) {
// if (err) console.log(err, err.stack); // an error occurred
// else console.log(data); // successful response
// });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment