Forked from jonarddoci/dynamodb delete all items in table
Created
April 9, 2018 00:37
-
-
Save springfred/ac38a68ae6c20513e141c6fce4e97875 to your computer and use it in GitHub Desktop.
Revisions
-
jonarddoci revised this gist
Feb 16, 2017 . 1 changed file with 17 additions and 9 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,22 +1,20 @@ var hashKey = "id"; var rangeKey = null; var tableName = "alert"; var scanParams = { TableName: tableName, }; docClient.scan(scanParams, function(err, data) { if (err) ppJson(err); // an error occurred else { data.Items.forEach(function(obj,i){ console.log(i); console.log(obj); var params = { TableName: scanParams.TableName, Key: buildKey(obj), ReturnValues: 'NONE', // optional (NONE | ALL_OLD) ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES) ReturnItemCollectionMetrics: 'NONE', // optional (NONE | SIZE) @@ -31,3 +29,13 @@ docClient.scan(params, function(err, data) { } }); function buildKey(obj){ var key = {}; key[hashKey] = obj[hashKey] if(rangeKey){ key[rangeKey] = obj[rangeKey]; } return key; } -
jonarddoci revised this gist
Sep 2, 2016 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ var scanParams = { TableName: 'table_name', }; @@ -9,7 +9,7 @@ docClient.scan(params, function(err, data) { console.log(i); console.log(obj); var params = { TableName: scanParams.TableName, Key: { // a map of attribute name to AttributeValue for all primary key attributes "sampleHashKey": obj.sampleHashKey, -
jonarddoci created this gist
Aug 27, 2016 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ var params = { TableName: 'table_name', }; docClient.scan(params, function(err, data) { if (err) ppJson(err); // an error occurred else { data.Items.forEach(function(obj,i){ console.log(i); console.log(obj); var params = { TableName: 'chatUserMapping', Key: { // a map of attribute name to AttributeValue for all primary key attributes "sampleHashKey": obj.sampleHashKey, "sampleRangeKey": obj.sampleRangeKey // more attributes... }, ReturnValues: 'NONE', // optional (NONE | ALL_OLD) ReturnConsumedCapacity: 'NONE', // optional (NONE | TOTAL | INDEXES) ReturnItemCollectionMetrics: 'NONE', // optional (NONE | SIZE) }; docClient.delete(params, function(err, data) { if (err) ppJson(err); // an error occurred else ppJson(data); // successful response }); }); } }); 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ dynamodb.listTables().eachPage(function(err, data) { if (err) { ppJson(err); // an error occurred } else if (data) { console.log(data); data["TableNames"].forEach(function(tablename, i) { console.log(tablename); var params = { TableName: tablename, }; dynamodb.deleteTable(params, function(err, data) { if (err) ppJson(err); // an error occurred else ppJson(data); // successful response }); }) } });