Last active
May 13, 2017 15:43
-
-
Save patrickbrandt/dcbf93c2cba0715c6654bc4b1902297b 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
const bb = require('bluebird'); | |
const AWS = require('aws-sdk'); | |
const s3 = new AWS.S3(); | |
const removeObject = (bucketName, obj) => { | |
const params = { | |
Bucket: bucketName, | |
Key: obj.Key, | |
}; | |
return s3.deleteObject(params).promise(); | |
}; | |
const emptyBucket = bb.coroutine(function* empty(bucketName) { | |
const data = yield s3.listObjects({ Bucket: bucketName }).promise(); | |
const tasks = data.Contents.map(obj => removeObject(bucketName, obj)); | |
yield Promise.all(tasks); | |
}); | |
emptyBucket(process.env.BUCKET_ONE) | |
.then(() => emptyBucket(process.env.BUCKET_TWO)) | |
.then(() => emptyBucket(process.env.BUCKET_THREE)) | |
.then(() => { /* do something */ }) | |
.catch(err => console.log(err)); | |
// or | |
Promise.all([ | |
emptyBucket(process.env.BUCKET_ONE), | |
emptyBucket(process.env.BUCKET_TWO), | |
emptyBucket(process.env.BUCKET_THREE)]) | |
.then(() => { /* do something */ }) | |
.catch(err => console.log(err)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment