AMI

An Amazon Machine Image (AMI) is a package that contains, among other things, the root filesystem with the OS (for example, Linux, Unix, or Windows) and additional software required to start up the system. To find the proper AMI, we will use aws ec2 describe-images. By default, the describe-images command will list all the public AMIs available which is way over 3 million by now. To get the best out of that command, it is important to combine it with the filter option to include the only AMI we would like to use. In our case, we want to use the following to filter out our AMI:

  • We want the name to be Amazon Linux AMI which designates the Linux distribution officially supported by AWS. Amazon Linux is based off Redhat/CentOS but includes a few extra packages to make the integration with other AWS services easy to do. You can read more about AWS Linux at http://amzn.to/2uFT13F.
  • We want to use the x84_64 bits version of it to match the architecture we will use.
  • The virtualization type should be HVM which stands for hardware virtual machine. This is the newest and best-performing type of virtualization.
  • GP2 support will let us use the newest generation of instances that don't come with "instance store," meaning that the servers that power our instances will be different from the servers that store our data.

In addition, we will sort the output by age and only look at the most recent AMI released:

$ aws ec2 describe-images --filters "Name=description,Values=Amazon Linux AMI * x86_64 HVM GP2"  --query 'Images[*].[CreationDate, Description, ImageId]' --output text | sort -k 1 | tail
2017-01-26T14:04:52.000Z Amazon Linux AMI 2016.09.1.20161221 x86_64 HVM GP2 ami-6cb4477a
2017-03-02T21:35:49.000Z Amazon Linux AMI 2016.09.1.20161221 x86_64 HVM GP2 ami-1f70a809
2017-03-20T09:30:49.000Z Amazon Linux AMI 2017.03.rc-0.20170320 x86_64 HVM GP2 ami-5b94234d
2017-03-28T01:56:01.000Z Amazon Linux AMI 2017.03.rc-1.20170327 x86_64 HVM GP2 ami-a672ccb0
2017-04-02T05:53:05.000Z Amazon Linux AMI 2017.03.0.20170401 x86_64 HVM GP2 ami-22ce4934
2017-04-17T08:14:59.000Z Amazon Linux AMI 2017.03.0.20170417 x86_64 HVM GP2 ami-c58c1dd3
2017-04-25T20:53:03.000Z Amazon Linux AMI 2016.09.1.20161221 x86_64 HVM GP2 ami-d8d64cce
2017-05-12T00:45:32.000Z Amazon Linux AMI 2017.03.0.20170417 x86_64 HVM GP2 ami-ab9aebbd
2017-06-17T21:56:53.000Z Amazon Linux AMI 2017.03.1.20170617 x86_64 HVM GP2 ami-643b1972
2017-06-23T23:35:49.000Z Amazon Linux AMI 2017.03.1.20170623 x86_64 HVM GP2 ami-a4c7edb2

As you can see, at this time, the most recent AMI ID is ami-a4c7edb2. This might differ by the time you execute the same command, as the Amazon vendors included regularly update their operating systems.

Using the aws cli --query option
On certain commands, the output can be very consequential. Taking the preceding example, if we only care about a subset of information, we can supplement the commands with a --query option to filter in only the information we want. This option uses the JMESPath query language.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset