amazon-web-servicesamazon-ec2amazon-ami

How to find an Amazon EC2 AMI if I only have the id?


What I have is AMI id (something like this ami-06358f49b5839867c) The case was AMI i see in this Karamel script

How do I find information about that AMI like Name, Region, ...?


Solution

  • Using describe-images, assuming the AMI is in the default region:

    aws ec2 describe-images --image-ids ami-06358f49b5839867c
    

    Otherwise you can specify the region, e.g.:

    aws ec2 describe-images --image-ids ami-06358f49b5839867c --region eu-west-1
    

    If you don't know the region where the AMI lives, then you'll have to use a loop to iterate over all AWS regions. In bash, this could look like:

    for region in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text | tr '\t' '\n')
    do 
      aws ec2 describe-images --image-ids ami-06358f49b5839867c --region "$region" &>/dev/null; 
      if [[ "$?" -eq 0 ]]; 
        then echo "AMI found in region ${region}!" && break
      fi 
    done