Easily Finding the Latest CoreOS AMI ID29 March 2017 · Filed in Tutorial
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
curlto retrieve it anytime you need it.
Putting these two reasons together, you end up with a command that looks something like this:
curl -s https://coreos.com/dist/aws/aws-stable.json | jq -r '."us-west-2".hvm'
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.
Now, if only other organizations would do the same…
Enjoy!Tags: AWS · CLI · CoreOS · Linux Previous Post: Canceling the OVS Cookbook Project Next Post: The Linux Migration: Corporate Collaboration, Part 3