deleting or emptying a s3 bucket

gregoire barret
Cover Image for deleting or emptying a s3 bucket

In some case like in initilization script, you might need to delete a AWS S3 bucket or delete the content of this bucket. In my case, i need to do it in comand line. But it's also possible to do it on the web console, or wich Java program.

Prerequise

I will consider you having a AWS CLI setup on your computer.

Deleteing a S3 Bucket

You can delete a bucket by this comand.

$ aws s3 rb s3://bucket-name --force

rb mean remove bucket --force parameter is required on the case we want to delete a non empty bucket.

Deleting content of a Bucket

In the case we don't want to delete a full bucket but only the content of this buclet, we can use the following comand line.

$ aws s3 rm s3://bucket-name --recursive

rm mean remove --recusive parameter will delete all the file under folders. by default it's will delete only the content the folder, but no sub folder.

If we don't want to delete all the bucket but only a folder of this bucket, we can specify the folder path,

$ aws s3 rm s3://bucket-name/folder-path --recursive