Created
March 14, 2019 20:04
-
-
Save sethkrasnianski/b15cdfb6d10175b305b05fcf80102d8a to your computer and use it in GitHub Desktop.
Batched DynamoDB Transactions - WIP
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 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