Created
January 28, 2019 14:37
-
-
Save jmaleonard/708c40815a3b7d666520651c14e39d5e to your computer and use it in GitHub Desktop.
Quick script to update all your DynamoDB tables to BillingMode: 'PAY_PER_REQUEST'
This file contains 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 AWS = require('aws-sdk'); | |
AWS.config.update({ region: 'eu-west-1' }); | |
let dynamoDB = new AWS.DynamoDB(); | |
let allTables = []; | |
const async = require('async'); | |
const sleep = require('sleep'); | |
function start() { | |
getDynamoDbTables({}).then((tables) => { | |
async.eachLimit(allTables, 1, updateTable, (error, result) => { | |
if(error){ | |
console.log(error); | |
process.exit(1); | |
} | |
console.log('All Done'); | |
process.exit(0); | |
}) | |
}) | |
} | |
function updateTable(TableName, callback) { | |
console.log(`Updating.........${TableName}`) | |
dynamoDB.updateTable({ | |
TableName, | |
BillingMode: 'PAY_PER_REQUEST' | |
}, (error) => { | |
if(error){ | |
console.log(error); | |
return callback(error); | |
} | |
console.log(`${TableName} has been updated`) | |
sleep.sleep(10); | |
return callback(); | |
}) | |
} | |
function getDynamoDbTables(params) { | |
return dynamoDB.listTables(params).promise().then((tables) => { | |
console.log('Got the current tables', tables) | |
allTables = allTables.concat(tables.TableNames); | |
if (tables.LastEvaluatedTableName) { | |
let params = { | |
ExclusiveStartTableName: tables.LastEvaluatedTableName | |
} | |
return getDynamoDbTables(params); | |
} | |
}) | |
}; | |
start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment