Skip to content

Instantly share code, notes, and snippets.

@longsangstan
Created April 28, 2017 09:16
Show Gist options
  • Save longsangstan/7d03d737928f6e0106fb5a03ddd79130 to your computer and use it in GitHub Desktop.
Save longsangstan/7d03d737928f6e0106fb5a03ddd79130 to your computer and use it in GitHub Desktop.
dynamodb modify all items
var scanAll = require("./scanAll");
var docClient = require("../aws").docClient;
var co = require("co");
var modifyAll = co.wrap(function*(table, action) {
var items = yield scanAll(table);
var promises = [];
for (var i = 0; i < items.length; i++) {
items[i] = action(items[i]);
var putShopParams = {
TableName: table,
Item: items[i]
};
console.log('new item: ' + JSON.stringify(items[i]));
promises.push(docClient.put(putShopParams).promise());
}
yield promises;
console.log("done");
return yield Promise.resolve();
});
module.exports = modifyAll;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment