When I want to launch an instance of Ubuntu on EC2, how do I find the right one? There are thousands of public images that have "Ubuntu" in their name. I am only interested in running the Official Ubuntu images. How do I now which AMI is the right one?
The success of Ubuntu as a platform and Ubuntu's commitment to refreshing AMIs means that there are literally thousands of of images on Amazon EC2 with "ubuntu"in their name. That, combined with and the lack of Ubuntu on the "Quick Start" menu makes selecting the right AMI a non-trivial task.
Some General Ubuntu Information
You already may be aware of these items, but I want to point them out for those who are just getting started with Ubuntu or EC2.
Easiest: Find AMIs From Your Web Browser
You can choose your interface for selecting images. Go to either:
https://cloud-images.ubuntu.com/locator/
At the bottom of this page, you can select the region, release, arch or root-store. You're only shown the most recent releases here. When you've made your selection, you can copy and paste the ami number, or just click on it to go right to the EC2 console launch page for that AMI.
or
Search through the Amazon EC2 Console
The EC2 Console is a graphical way to sort through AMIs and select one to launch. To Launch an Official Ubuntu Image here, follow the steps below.
Select the region you want in the top left, under 'Navigation' Example: "Us East (Virginia)"
Click "AMIs" Do not click "Launch Instance" [see note below]
for 'Viewing', select "All Images"
Limit the results to Ubuntu Stable Release images by typing ubuntu-images/
You should expand the 'AMI Name' field as wide as possible (maybe shrink the others).
Limit the results to a specific release by appending '.*'.
For example: ubuntu-images/.*10.04
Limit the results to a given arch by appending '.*i386' or '.*amd64'
Note: If you want to run a m1.small or c1.medium, you need 'i386'. If you want to run a t1.micro, you will need to select an 'ebs' image.
Sort your results by AMI Name and make selection
By sorting by AMI name, you can more easily see the newest AMI for a given set. Each AMI ends with a number in the format YYYYMMDD (year,month,day). You want the most recent one.
Verify the Owner is 099720109477!
Any user can register an AMI under any name. Nothing prevents a malicious user from registering an AMI that would match the search above. So, in order to be safe, you need to verify that the owner of the ami is '099720109477'.
If "Owner" is not a column for you, click "Show/Hide" at the top right and select "Owner" to be shown.
Click on the AMI name, then Click 'Launch'
Notes
Source 1: ubuntu-smoser.blogspot.com
Source 2: ubuntu.com
New and improved version.
Basically grabs raw data used for ubuntu's ami finding page, and uses jq to parse out the row I want then a grep to pull out the value. Much faster than the old version.
-- original version
Here's another example. I just wrote this to fetch the latest trusty AMI id. It uses the aws cli tool to query the API, using the fact that the names sort in date order to get the latest.
It works in 2 parts. The first part gets all the AMIs for ubuntu trusty that meet the various criterion (ebs, x86_64, and the name pattern). It pulls out the Name and sorts by it. The names are formatted so that sorting them sorts by date so the last one will be the newest one. This name is then assigned to the 'name' variable.
The second part uses that name to request the AMI ID for the AMI with that name. It parses out just the id and assigns it to 'ami_id'.
using ruby aws-sdk, you can programatically discover the latest Ubuntu AMI like this
You can use https://cloud-images.ubuntu.com/locator/ec2/ which provide a comprehensive comparison based on version, release date etc.
Search for the version, region you want and sort based on release date to get the latest version.
There is a comprehensive list of available Official AMIs on the Ubuntu Cloud Portal. You an find additional resources regarding Canonical's Official EC2 AMI releases in the Ubuntu Help: EC2 Starts Guide and a raw directory of all the AMIs released by Canonical in Ubuntu EC2 Images
I thought it would be useful to demonstrate how to do this using with Ansible by using the ec2_ami_find module.
At the time of writing (2017-06-07) in the ap-southeast-2 region AWS will suggest these Ubuntu LTS images if you start an EC2 instance manually from the console:
This is in line with their recommendations to use HVM virtualization and EBS backed SSD Volumes.
To get the same AMIs that AWS recommend you can use the following tasks:
Which gives the following output:
If you compare the AMI ids returned by the playbook you can see AWS do not recommend the latest available image but rather the second or third latest. I don't know what criteria/heuristic they are using here.