簡體   English   中英

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

[英]How to find AMI ID of CentOS 7 image in AWS Marketplace?

我一直在通過登錄 AWS 站點、點擊“啟動”按鈕並按照規定的步驟啟動 EC2 實例。 現在我想從 Ansible 腳本啟動實例,為此我(認為我)需要我希望啟動的圖像的 AMI ID。

問題是我從“Marketplace”啟動圖像,但找不到 AMI ID。 特別是我使用的是 Centos 7 圖像。 這個在web界面很容易找到,去市場搜索“centos”,我要的鏡像是第一個找到的,但是提供的鏡像信息好像沒有我的AMI ID需要從腳本啟動它。 解決方法是手動啟動映像,然后在檢查正在運行的映像時提供 AMI ID。 但是有沒有更簡單的方法找到它呢?

CentOS 將他們的 AMI 產品代碼發布到他們的wiki wiki 提供了最新 CentOS 7 AMI 的以下信息:

  • 所有者: aws-marketplace
  • 產品代碼: aw0evgkw8e5c1q413zgy5pjce

使用此信息,我們可以使用 AWS CLI 查詢描述圖像

示例:

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

輸出:

ami-6d1c2007

此查詢返回單個 AMI ID,通過按創建日期對集合進行排序,然后選擇集合中的最后一個(最近的)元素來選擇。

根據 CentOS wiki, multiple AMI ids may be associated with a product key ,因此雖然此查詢目前僅返回一個 AMI,因為當前僅存在一個匹配此產品的...將來如果為此產品創建新的 AMI無論出於何種原因,此查詢都將返回它。

在這個頁面簽到

AWS 一直在改變“aws 市場”用戶界面。 現在( 2020 年)我們在 AWS Marketplace 本身的“配置此軟件”頁面中獲取 ami id。

步驟:

  1. 搜索並定位圖像。 單擊圖像。
  2. 點擊右上角的“繼續訂閱”
  3. 在下一個窗口中,單擊“繼續配置”
  4. 在下一個窗口中,找到找到的 Ami ID。 我們可以更改軟件版本以獲得不同的 ami Id。

如果您正在尋找所有 Centos7 鏡像

$ aws 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  |

添加可用於 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 |

我在這里使用了其他答案作為在 Terraform 中測試 AMI 查找的好方法。

使用...

aws ec2 describe-images \
    --owners aws-marketplace \
    --filters '[
        {"Name": "name",                "Values": ["CentOS Linux 7*"]},
        {"Name": "virtualization-type", "Values": ["hvm"]},
        {"Name": "architecture",        "Values": ["x86_64"]},
        {"Name": "image-type",          "Values": ["machine"]}
    ]' \
    --query 'sort_by(Images, &CreationDate)[-1]' \
    --region us-east-1 \
    --output json

...讓我有機會嘗試和錯誤查找

data "aws_ami" "centos" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "virtualization-type"
    values = ["hvm"]
  }

  filter {
    name   = "architecture"
    values = ["x86_64"]
  }

  filter {
    name   = "image-type"
    values = ["machine"]
  }

  filter {
    name   = "name"
    values = ["CentOS Linux 7*"]
  }
}

resource "aws_launch_configuration" "launch_configuration" {
  name_prefix = "${var.name}-"

  image_id = "${data.aws_ami.centos.image_id}"
  instance_type        = "t2.nano"
  iam_instance_profile = "${aws_iam_instance_profile.instance_profile.name}"
  security_groups      = ["${aws_security_group.lc_security_group.id}"]

  user_data = "${data.template_file.user_data.rendered}"

  lifecycle {
    create_before_destroy = true
  }
}

它不適合我。 出現以下錯誤 - 未找到匹配過濾器的 AMI:{過濾器:[{名稱:“產品代碼”,值:[“aw0evgkw8e5c1q413zgy5pjce”]},{名稱:“虛擬化類型”,值:[“hvm”]} ], 所有者: ["aws-marketplace"] }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM