I using Packer for generate my AMIs in AWS.
I see the high number the AMI’s accumulate in my account.
How to removing the old images after generate the last image?
How to removing the images without removing the AMI being used?
packer version: 1.4.2
Hi, I think you’re experiencing a bug that was resolved in the 1.4.5 release. Please upgrade to a new version of Packer, and Packer will correctly clean up those intermediary images for you. issue line: https://github.com/hashicorp/packer/issues/8116 PR: https://github.com/hashicorp/packer/pull/8307
Hi @SwampDragons, thank’s for your answer.
But the problem is that the old image that was generated, and not the intermediate image.
When I run the packer, a new image is created.
Then I need to remove the old images that have already been used.
If you are asking about the older successfully created images, I am sure Packer has no way to automatically clean them up (and should it even ?)
I would recommend to use an
awscli command to query images by timestamp and clean them up, and keep it separate from the Packer workflow.
*** Thought while typing: I wonder if Terraform has this capability; “query images < timestamp and then delete them” (this is just a thought)
The only way Packer will do that by default is if the new image has the same name as the old one, and you use the force_deregister option in the template.
Otherwise, we don’t manage your image for you. We think that’s outside the scope of the tool. Here’s a disclaimer we have in our docs:
The builder does not manage AMIs. Once it creates an AMI and stores it in your account, it is up to you to use, delete, etc. the AMI.