Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Deleting Amazon S3 Bucket with A Lot of Files
# Here is a short script that can mass delete files in an Amazon S3 bucket. It is limited to a 1,000 keys at a time
use Net::Amazon::S3;
my $s3 = Net::Amazon::S3->new({
aws_access_key_id => 'ACCESS_ID',
aws_secret_access_key => 'ACCESS_KEY',
retry => 1,
my $bucket = $s3->bucket("BUCKET") or die $s3->err . ": " . $s3->errstr;
my $response = $bucket->list or die $s3->err . ": " . $s3->errstr;
foreach my $key (@{$response->{keys}}) {
my $key_name = $key->{key};
print "Deleting '$key_name'n";
$bucket->delete_key($key_name) or die $s3->err . ": " . $s3->errstr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.