bonclay7 / aws-amicleaner

Cleanup your old unused ami and related snapshots
MIT License
362 stars 132 forks source link

Purge AMI ID with timestamp or commit sha #15

Closed monyth closed 8 years ago

monyth commented 8 years ago

Hello,

Do you think it's possible to delete AMI ID older than 10 days or with commit sha?

bonclay7 commented 8 years ago

Hello ! Right now, it isn't possible to clean with older than 10 days, but it could be a nice feature...

But you can remove with a commit sha if it is a tag, you can try something like that :

amicleaner/cli.py --mapping-key tags --mapping-values commit_sha --keep-previous 1

I set keep-previous to zero because I suppose you have only one AMI per commit

It won't work if you set keep-previous to 0. The tool forces history, the minimum value is 1

monyth commented 8 years ago

And you can delete with timestamp? When you use keep-previous with 10 that's mean you keep 10 last versions of AMI?

bonclay7 commented 8 years ago

No, there isn't a timestamp yet ... And the keep-previous argument is indeed a way to preserve amis sorted on creation-date for those who share a same tag.

For your use case, I think you can use the following syntax :

amicleaner/cli.py --mapping-key name --mapping-values test1 --keep-previous 2

Default values : ==>
mapping_key : name
mapping_values : ['test1']
keep_previous : 2

Retrieving AMIs to clean ...

AMIs to be removed:
+------------+------------+
| Group name | candidates |
+------------+------------+
|   test1    |     11     |
+------------+------------+
Do you want to continue and remove 11 AMIs [y/N] ? :

It will regroup all the AMIs which have the same name, reverse sort them on the creation-date, and remove until keep-previous argument which is 4 by default.

You can add --full-report option to have a verbose output and see what AMIs are candidates

monyth commented 8 years ago

The method work but I have an issue with delete which generate an error and stop. image

In parallel the delete for AMI in error is done after each minutes.

bonclay7 commented 8 years ago

Do you have the last version of the repo ? This issue has already been fixed I've just tested, and it works fine :smile:

amicleaner/cli.py --mapping-key name --mapping-values test1 --full-report --keep-previous 10                                                                    
monyth commented 8 years ago

The last version of repo ? Where can I find info?

bonclay7 commented 8 years ago

just a git clone of the project. But I think I understand what's happening here. AMI deregistering is asynchronous, and it is scheduled by AWS. In my case, the deregistering operation was done instantly so I was able to remove the related snapshot. Interesting ...

monyth commented 8 years ago

Same after git clone with last version I have same issue. 1 AMI id is deleted but not other. I have an error message and after script stopped.