Find AWS EC2 AMI owner ID

02 Sep 2021 in TIL

I wanted to deploy a new Ubuntu EC2 instance to AWS using Pulumi, but needed the owner ID of the AMI for the search:

js
const ami = pulumi.output(
aws.ec2.getAmi({
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
],
owners: ["099720109477"], // This owner ID is Canonical
mostRecent: true,
})
);

I found the AMI ID on Ubuntu Cloud Images, but it didn’t return the owner ID.

The simplest way to find the owner of a given image is to use the aws ec2 describe-images command like so:

bash
aws ec2 describe-images --image-ids ami-0194c3e07668a7e36 --region eu-west-2 | jq ".Images[0].OwnerId"

This will return the owner ID you’re looking for (099720109477 for Canonical).