How to List and Filter Available AMIs with AWS CLI and Powershell
2 min readOct 6, 2023
The aim of this page📝 is to explain how to use AWS CLI to list and filter Amazon Machine Images (AMIs) based on the particular example of filtering AMIs with names containing “example” (I am anonymizing)
aws ec2 describe-images --filters "Name=name,Values=*example*" --output json |
ConvertFrom-Json |
% {$_.Images} |
Select Name, OwnerId
- AWS CLI is a unified tool that provides a consistent interface for interacting with all parts of AWS.
- AMIs are templates that contain a software configuration (for example, an operating system, an application server, and applications).
- You can use the
describe-images
command in AWS CLI to list AMIs. - To filter the images by name, you can use the
--filters
option with theName=name,Values=*example*
parameter. - The asterisk (*) is a wildcard that matches zero or more characters.
- This command will return a list of AMI images owned by your account (
self
) and whose names contain "example". - Remember to configure your AWS CLI with the correct credentials and region before running this command.
- If you have multiple profiles, you can specify the profile by adding
--profile yourprofilename
to the command. - This command will return a JSON output. If you want to make it more readable or filter it further, you can use tools like
jq
. - In PowerShell, you can use the
ConvertFrom-Json
cmdlet to parse the JSON output from the AWS CLI command. - Then, you can pipe it to
Select-Object
to select only the name of the image and the owner ID. - The command you’re using queries the AMIs that are available to your AWS account.
- When you specify
--filters "Name=name,Values=*example*"
in the command, it returns only the AMIs that have "example" in their name. - When you specify
--owners self
in the command, it returns only the AMIs that are owned by your account. - If you don’t include the
--owners
option, the command returns all AMIs that you have launch permissions for. - This includes public AMIs, private AMIs owned by other AWS accounts that have been shared with you, and your own private AMIs.