Scott's WeblogThe weblog of an IT pro focusing on cloud computing, Kubernetes, Linux, containers, and networking

Easily Finding the Latest CoreOS AMI ID

It seems as if finding the right Amazon Machine Image (AMI) ID for the workload you’d like to deploy can sometimes be a bit of a challenge. Each combination of region and AMI produces a unique ID, so you have to look up the AMI for the particular region where you’re going to deploy the workload. This in and of itself wouldn’t be so bad, but then you have to wade through multiple versions of the same AMI in each region. Fortunately, if you’re using CoreOS Container Linux on AWS, there’s an easy way to find the right AMI ID. Here’s how it works.

CoreOS publishes a JSON feed of the latest AMI for each of their channels (stable, beta, and alpha). You can find links to these JSON feeds on this page. This is powerful for 2 reasons:

Because it’s available via HTTP, you can use curl to retrieve it anytime you need it.

Because it’s in JSON, you can use jq (see my post on jq for more information) to easily parse it to find the information you need. (Not super comfortable with JSON? Check out my introductory post.)

Putting these two reasons together, you end up with a command that looks something like this:

This command pulls the stable JSON feed, then parses it using jq to look for the “us-west-2” AMI. Note the somewhat odd quoting necessary for jq to work properly. The -s parameter to curl suppresses any output, and the -r parameter to jq returns plain, unformatted (raw) text. Use some Bash command substitution to assign the output of this command to a variable and you’ve got an easy, always up-to-date way of determining the AMI ID for the latest release of CoreOS Container Linux in your AWS region of choice.