This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ishibashi_y
committed
Jul 8, 2019
1 parent
50f9a82
commit b73da7a
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import AWS from 'aws-sdk'; | ||
|
||
const S3 = new AWS.S3(); | ||
const bucketName = process.env.BUCKET_NAME; | ||
|
||
const main = async () => { | ||
if (!bucketName) { | ||
throw new Error('BUCKET_NAME is not specified'); | ||
} | ||
|
||
const versions = (await S3.listObjectVersions({ | ||
Bucket: bucketName | ||
}).promise()).Versions; | ||
|
||
// Delete one by one | ||
for (const version of versions) { | ||
await S3.deleteObject({ | ||
Bucket: bucketName, | ||
Key: version.Key, | ||
VersionId: version.VersionId | ||
}).promise(); | ||
} | ||
|
||
await S3.deleteBucket({ | ||
Bucket: bucketName | ||
}).promise(); | ||
}; | ||
|
||
main(); |