Jor-El
Jor-El

Reputation: 437

How to delete a bucket starting with a name using aws cli?

Is there any command of aws cli to delete all buckets starting with a specific name?

When I ran:

aws s3 ls

list of buckets

I got so many buckets, we need to frequently cleanup. If got any command, I can create a pipeline for it in gitlab and use that to cleanup.

Like you observe, I want to delete all the buckets starting with somename-

I tried using

aws s3 rb --force s3://somename-*

It didn't work.

Upvotes: 0

Views: 843

Answers (1)

Anon Coward
Anon Coward

Reputation: 10832

There's no built in way to accomplish this. On Unix-like platforms, you can list all of the buckets and use some tools to filter the list and call in the CLI to remove all of the buckets that match some pattern:

aws s3api list-buckets --query 'Buckets[].[Name]' --output text | grep "^somename-" | xargs -n1 -IB echo aws s3 rb s3://B

Remove the "echo " after verifying the command will remove the buckets you want removed.

Upvotes: 3

Related Questions