Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete lot of objects named with common prefix from S3 bucket?

Tags:

amazon-s3

I have files in S3 bucket, and their names have the following format:

username#file_id#...

How to remove all john#doe#* items, without listing them? There are thousands of them, so when user request my app to delete all of them, he has to wait.

like image 770
Illarion Kovalchuk Avatar asked Jul 05 '10 10:07

Illarion Kovalchuk


People also ask

Can you delete an S3 bucket with objects in it?

For buckets without versioning enabled, you can delete all objects directly and then delete the bucket. For buckets with versioning enabled, you must delete all object versions before deleting the bucket. For instructions on creating and testing a working sample, see Testing the Amazon S3 Java Code Examples.

How will you delete a bucket that has multiple files and folders in it?

To delete multiple files from an S3 Bucket with the AWS CLI, run the s3 rm command, passing in the exclude and include parameters to filter the files the command is applied to. Let's run the command in test mode first.

How do I remove a prefix from my Galaxy S3?

You can use aws s3 rm command using the --include and --exclude parameters to specify a pattern for the files you'd like to delete. which will delete all files that match the "abc_1*" pattern in the bucket. Thanks, worked fine.


1 Answers

For anyone who stumbles upon this now, you can create a lifecycle rule to either delete or set expiration of files with a certain prefix.

like image 64
4kshay Avatar answered Nov 09 '22 02:11

4kshay