阅读背景:

如何在AWS Marketplace中查找CentOS 7映像的AMI ID?

来源:互联网 

I have been launching EC2 instances by logging in to the AWS site, hitting the "Launch" button and following the proscribed steps. Now I'd like to launch instance from an Ansible script, and to do this I (think I) need the AMI ID of the image I wish to launch.

我已经通过登录AWS站点启动EC2实例,点击“启动”按钮并遵循禁止的步骤。现在我想从Ansible脚本启动实例,为此我想(我想)需要我想要启动的图像的AMI ID。

The problem is that I am launching an image from the "Marketplace", and I cannot find the AMI ID. In particular I'm using the Centos 7 image. This is easy to find in the web interface, just go to the marketplace and search for "centos", the image I want is the first one found, but the information provided about the image doesn't seem to include the AMI ID that I need to launch it from a script. The workaround is to manually launch an image, and then when inspecting the running image, the AMI ID is given. But is there an easier way to find it?

问题是我正在从“市场”发布图像,但我找不到AMI ID。特别是我正在使用Centos 7图像。这很容易在网页界面找到,只是去市场搜索“centos”,我想要的图像是第一个找到的图像,但提供的图像信息似乎不包括我的AMI ID需要从脚本启动它。解决方法是手动启动映像,然后在检查正在运行的映像时,会给出AMI ID。但是有更简单的方法来找到它吗?

2 个解决方案

#1


23  

CentOS publishes their AMI product codes to their wiki. The wiki provides the following information for the latest CentOS 7 AMI:

CentOS将他们的AMI产品代码发布到他们的维基。维基为最新的CentOS 7 AMI提供以下信息:

  • Owner: aws-marketplace
  • 所有者:aws-marketplace
  • Product Code: aw0evgkw8e5c1q413zgy5pjce
  • 产品代码:aw0evgkw8e5c1q413zgy5pjce

Using this information, we can query describe-images with the AWS CLI:

使用此信息,我们可以使用AWS CLI查询describe-images:

Example:

例:

aws ec2 describe-images \
    --owners 'aws-marketplace' \
    --filters 'Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce' \
    --query 'sort_by(Images, &CreationDate)[-1].[ImageId]' \
    --output 'text'

Output:

输出:

ami-6d1c2007

This query returns a single AMI ID, selected by sorting the collection by creation date and then selecting the last (most recent) element in the collection.

此查询返回单个AMI ID,通过按创建日期对集合进行排序,然后选择集合中的最后一个(最新)元素来选择。

Per the CentOS wiki, multiple AMI ids may be associated with a product key, so while this query would currently only return a single AMI because only one matching this product currently exists... in the future if a new AMI is created for this product code for any reason this query will return it instead.

根据CentOS维基,多个AMI ID可能与产品密钥相关联,因此虽然此查询目前仅返回单个AMI,因为当前只存在一个与此产品匹配的产品...将来如果为此产品创建新的AMI此查询将返回它的任何原因的代码。

#2


0  

If you are looking for all Centos7 images

如果您正在寻找所有Centos7图像

$ aws --region us-west-2 ec2 describe-images --owners aws-marketplace --filters Name=product-code,Values=aw0evgkw8e5c1q413zgy5pjce --query 'Images[*].[CreationDate,Name,ImageId]' --filters "Name=name,Values=CentOS Linux 7*" --region us-west-2 --output table | sort -r
|  2018-06-13T15:58:14.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1805_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-77ec9308.4  |  ami-3ecc8f46  |
|  2018-05-17T09:30:44.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1804_2-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-55a2322a.4   |  ami-5490ed2c  |
|  2018-04-04T00:11:39.000Z|  CentOS Linux 7 x86_64 HVM EBS ENA 1803_01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-8274d6ff.4  |  ami-0ebdd976  |
|  2017-12-05T14:49:18.000Z|  CentOS Linux 7 x86_64 HVM EBS 1708_11.01-b7ee8a69-ee97-4a49-9e68-afaee216db2e-ami-95096eef.4   |  ami-b63ae0ce  |

add to it similar query available for RedHat

添加到RedHat可用的类似查询

aws  ec2 describe-images --owners 309956199498 --query 'Images[*].[CreationDate,Name,ImageId]' --filters "Name=name,Values=RHEL-7.?*GA*" --region us-east-1 --output table | sort -r
|  2018-03-23T20:42:08.000Z |  RHEL-7.5_HVM_GA-20180322-x86_64-1-Hourly2-GP2  |  ami-6871a115 |
|  2017-08-08T15:37:31.000Z |  RHEL-7.4_HVM_GA-20170808-x86_64-2-Hourly2-GP2  |  ami-c998b6b2 |
|  2017-07-24T15:44:39.000Z |  RHEL-7.4_HVM_GA-20170724-x86_64-1-Hourly2-GP2  |  ami-cdc999b6 |
|  2016-10-26T22:32:29.000Z |  RHEL-7.3_HVM_GA-20161026-x86_64-1-Hourly2-GP2  |  ami-b63769a1 |
|  2015-11-12T21:06:58.000Z |  RHEL-7.2_HVM_GA-20151112-x86_64-1-Hourly2-GP2  |  ami-2051294a |
|  2015-02-25T20:24:23.000Z |  RHEL-7.1_HVM_GA-20150225-x86_64-1-Hourly2-GP2  |  ami-12663b7a |
|  2015-02-09T22:54:40.000Z |  RHEL-7.0_HVM_GA-20150209-x86_64-1-Hourly2-GP2  |  ami-60a1e808 |
|  2014-10-17T20:29:24.000Z |  RHEL-7.0_HVM_GA-20141017-x86_64-1-Hourly2-GP2  |  ami-a8d369c0 |
|  2014-05-28T19:17:11.000Z |  RHEL-7.0_GA_HVM-x86_64-3-Hourly2               
|  ami-785bae10 |

分享到: