wallix / awless

A Mighty CLI for AWS
http://awless.io/
Apache License 2.0
4.98k stars 263 forks source link

How to empty an S3 Bucket and ECR Registry #111

Closed c2xbrhdj6u4qs15 closed 7 years ago

c2xbrhdj6u4qs15 commented 7 years ago

Hi,

I am wondering how to empty an S3Bucket or a ECR Registry to be able to delete the Bucket or the ECR Registry?

Thanks in advance

fxaguessy commented 7 years ago

For now, you can not directly do that with awless. However, this can be done with bash one-liners:

To empty a s3bucket, replace your-bucket (2 times) with the name of the bucket you want to empty and run:

awless list s3objects --filter bucket=your-bucket --format tsv | tail -n +2 | cut -f 1 | xargs -n1 awless delete s3object bucket=your-bucket name=

When you have checked that the output is correct (it attempts to delete the correct objects), add the -f flag to awless delete s3object, in order to disable the confirmation prompt.

To empty a registry, i.e. delete all the repositories of an account registry, replace your-account with the ID of the account of the ECR registry. Note that you can know your account with awless whoami --account-only and if you want to empty the registry of your current account, you can omit this parameter:

awless list repositories --filter account=your-account --format tsv | tail -n +2 | cut -f 1 | xargs -n1 awless delete repository force=true account=your-account name=

When you have checked that the output is correct (it attempts to delete the correct objects), add the -f flag to awless delete repository, in order to disable the confirmation prompt.

c2xbrhdj6u4qs15 commented 7 years ago

Thanks for your response. I am going to try this out. Regards