Last active
March 22, 2024 16:00
-
-
Save amosshapira/8df5e76be82eb774e8fd7ae22363fcee to your computer and use it in GitHub Desktop.
Find self-owned AMI's which are not used by any instances or launch configurations in a region
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Find self-owned AMI's which are not used by any instances or launch configurations in the default region. | |
| comm -23 \ | |
| <(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \ | |
| <((aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text; | |
| aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[].[ImageId]' --output text) | sort -u) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Find self-owned AMI's which are not used by any instances or launch configurations in the default region. | |
| # Output with details in descending order of name and creation date. | |
| aws ec2 describe-images --image-ids \ | |
| $(comm -23 \ | |
| <(aws ec2 describe-images --owner self --query 'Images[].[ImageId]' --output text | sort) \ | |
| <((aws ec2 describe-instances --query 'Reservations[].Instances[].[ImageId]' --output text; \ | |
| aws autoscaling describe-launch-configurations --query 'LaunchConfigurations[].[ImageId]' --output text) | \ | |
| sort -u | \ | |
| tr '\n' ' ')) \ | |
| --query 'Images[].[ImageId,Name,CreationDate]' \ | |
| --output text | \ | |
| sort -t $'\t' -k 2 -k 3.1,3.4nr -k 3.6,3.7nr -k 3.9,3.10nr -k 3.12,3.13nr -k 3.15,3.16nr -k 3.18,3.19nr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you very much for the update. I'm not currently in a position to test this but your improvement could make sense.