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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With