Skip to content

Instantly share code, notes, and snippets.

@tankhuu
Created July 24, 2018 12:47
Show Gist options
  • Save tankhuu/0b89b93e6de33f5f323fbd0d8259d766 to your computer and use it in GitHub Desktop.
Save tankhuu/0b89b93e6de33f5f323fbd0d8259d766 to your computer and use it in GitHub Desktop.
// Function creation && Process Array in Sequence
const stopRDSMySQL = async ({DBInstanceIdentifier}) => {
try {
const rds = new AWS.RDS();
const {DBInstances} = await rds.describeDBInstances({DBInstanceIdentifier}).promise();
const listOfStoppedDBInstances = [];
if(!_.isEmpty(DBInstances)) {
for(const DBInstance of DBInstances) {
const {DBInstanceStatus, DBInstanceIdentifier} = DBInstance;
if(DBInstanceStatus === 'available') {
console.log(`Gonna stop ${MODULE_NAME}.stopRDSMySQL.dbInstance.${DBInstanceIdentifier}:`);
listOfStoppedDBInstances.push(DBInstanceIdentifier);
}
}
}
return listOfStoppedDBInstances;
} catch(err) {
throw new Error(`${MODULE_NAME}.stopRDSMySQL: ${err.method}`);
}
};
// Function creation and process array in parallel
const stopRDSMySQL = async ({DBInstanceIdentifier}) => {
try {
const rds = new AWS.RDS();
const {DBInstances} = await rds.describeDBInstances({DBInstanceIdentifier}).promise();
const listOfStoppedDBInstances = [];
if(!_.isEmpty(DBInstances)) {
await Promise.all(DBInstances.map(DBInstance => {
const {DBInstanceStatus, DBInstanceIdentifier} = DBInstance;
if(DBInstanceStatus === 'available') {
console.log(`Gonna stop ${MODULE_NAME}.stopRDSMySQL.dbInstance.${DBInstanceIdentifier}:`);
listOfStoppedDBInstances.push(DBInstanceIdentifier);
}
}));
}
return listOfStoppedDBInstances;
} catch(err) {
throw new Error(`${MODULE_NAME}.stopRDSMySQL: ${err.method}`);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment