Created
July 24, 2018 12:47
-
-
Save tankhuu/0b89b93e6de33f5f323fbd0d8259d766 to your computer and use it in GitHub Desktop.
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
// 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