I want to write a script that prints out all the AMIs created before (or after) a certain date. However, I am really struggling to do this so any help is sincerely appreciated.
I don't have much now, but this is what I have so far:
aws ec2 describe-images > c:\ami_names.txt
Any tips on how to filter out just for the AMIs created before a certain date?
To find a Linux AMI using the AMIs page Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/ . From the navigation bar, select the Region in which to launch your instances. You can select any Region that's available to you, regardless of your location. In the navigation pane, choose AMIs.
Go to VPC dashboard https://console.aws.amazon.com/vpc/home and click on Running instances -> See all regions .
You can use the AWS CLI to list your instances and view information about them. You can list all your instances, or filter the results based on the instances that you're interested in. The following examples show how to use the aws ec2 describe-instances command. The following command lists all your instances.
Here's an example that queries for all images created after April 1st, 2016:
aws ec2 describe-images --query 'Images[?CreationDate>=`2016-04-01`][]'
I believe you should be able to expand on that example to get everything you need.
You can use jq to filter the response
The command to get the AMIs created before a particular date,
aws ec2 describe-images --owners self --output json | jq '.Images[] | select(.CreationDate<'$GET_AMI') | {ImageId}' | jq --raw-output '.ImageId'))
This just gives the list of AMI-ids.
Remove | jq --raw-output '.ImageId'))
if you need the json format.
Remove | {ImageId}
if you need all the attributes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With