clean_old_amis.sh 626 B

12345678910111213141516171819202122
  1. #! /bin/bash
  2. #
  3. # Requires amicleaner:
  4. # ```
  5. # pip3 install aws-amicleaner
  6. # ```
  7. VERSIONS_TO_KEEP=3
  8. for profile in mdr-common-services-gov mdr-common-services; do
  9. echo
  10. echo ==== Cleaning $profile
  11. echo
  12. AWS_PROFILE=${profile} amicleaner --full-report --keep-previous ${VERSIONS_TO_KEEP} --mapping-key tags --mapping-values Description Release --check-orphans
  13. echo =========== Done
  14. echo
  15. done
  16. echo
  17. echo AMIs listed under \'no-tags\' were likely orphaned by packer via ctrl-c. Clean them up via:
  18. echo \ \ aws ec2 deregister-image --image-id ami-xxxxxxx --profile mdr-common-services-gov
  19. echo and then rerun $0
  20. echo