Skip to content

Instantly share code, notes, and snippets.

@jonarddoci
Last active March 4, 2020 13:07
Show Gist options
  • Save jonarddoci/a1d595236854c6dbfa1a727ea09506ea to your computer and use it in GitHub Desktop.
Save jonarddoci/a1d595236854c6dbfa1a727ea09506ea to your computer and use it in GitHub Desktop.
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)
};
docClient.delete(params, function(err, data) {
if (err) ppJson(err); // an error occurred
else ppJson(data); // successful response
});
});
}
});
function buildKey(obj){
var key = {};
key[hashKey] = obj[hashKey]
if(rangeKey){
key[rangeKey] = obj[rangeKey];
}
return key;
}
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
});
})
}
});
@dejanvasic85
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment