Skip to content

Commit

Permalink
don't teardown on update (#23)
Browse files Browse the repository at this point in the history
* don't teardown on update

* using batchwrite
  • Loading branch information
jsdtaylor committed May 7, 2020
1 parent 634ccd6 commit f577ff2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ const AWS = require('aws-sdk');
const s3 = new AWS.S3();
const writeTypeFromAction = (action) => {
if (action === "put")
if (action === "Put")
return "Item";
if (action === "delete")
if (action === "Delete")
return "Key";
}
Expand All @@ -79,17 +79,28 @@ const run = async (filename, action) => {
convertEmptyValues: true
});
console.log('sending data to dynamodb');
for(let i = 0; i < seed.length;i++) {
await documentClient[action]({
TableName: '${props.table.tableName}',
[writeTypeFromAction(action)]: seed[i]
do {
const requests = [];
const batch = seed.splice(0, 25);
for (let i = 0; i < batch.length; i++) {
requests.push({
[action + "Request"]: {
[writeTypeFromAction(action)]: batch[i]
}
});
}
await documentClient.batchWrite({
RequestItems: {
'${props.table.tableName}': [...requests]
}
}).promise();
};
}
while (seed.length > 0);
console.log('finished sending data to dynamodb');
}
exports.handler = async (event) => {
if (event.mode === "delete" || event.mode === "update")
if (event.mode === "delete")
await run("teardown.json", "delete");
if (event.mode === "create" || event.mode === "update")
await run("setup.json", "put");
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aws-cdk-dynamodb-seeder",
"version": "1.37.0",
"version": "1.37.1",
"description": "A simple CDK JSON seeder for DynamoDB",
"scripts": {
"build": "jsii",
Expand Down

0 comments on commit f577ff2

Please sign in to comment.