如何查找适用于AMI的实例类型列表

16

使用来自ap-south-1区域的ami-0fd3c3c68a2a8066fhttp://cloud-images.ubuntu.com/locator/ec2/,但无法对其使用t2.micro实例类型。

Error: Error launching source instance: InvalidParameterValue: The architecture 'x86_64' of the specified instance type does not match the architecture 'arm64' of the specified AMI. Specify an instance type and an AMI that have matching architectures, and try again. You can use 'describe-instance-types' or 'describe-images' to discover the architecture of the instance type or AMI.

如何在使用 Terraform 启动实例之前查找适用于 AMI 的实例类型列表


那么你打算如何处理输出?你可能不想为 AMI 支持的每个实例类型都创建一个实例,也不想只使用 AMI 支持的第一个实例类型,是吗? - ydaetskcoR
我不确定如何在我的Terraform脚本中加入一些智能,以便我只能选择可用于AMI的实例类型。 - Rpj
1
但是这是一个你需要静态知道的东西,而不是在运行时知道的,对吧?如果你有一个arm64 AMI,那么你可能会看看你可以在哪些实例类型上运行它,但你不希望Terraform根据过滤器的排序来做出任意决定关于实例类型。 - ydaetskcoR
请点击以下链接查看与Amazon Linux AMI兼容的实例类型矩阵:https://aws.amazon.com/amazon-linux-ami/instance-type-matrix/ - Pat Myron
2个回答

10
使用AWS CLI,您可以使用describe-instance-types命令:describe-instance-types
aws ec2 describe-instance-types --filters Name=processor-info.supported-architecture,Values=arm64 --query "InstanceTypes[*].InstanceType" --output text

例如,输出结果:
r6gd.large  m6g.metal   m6gd.medium c6gd.metal  m6gd.12xlarge   c6g.16xlarge    r6g.large   r6gd.medium r6g.8xlarge m6gd.metal  r6gd.xlarge t4g.medium  r6gd.2xlarge    m6gd.xlarge c6g.xlarge  c6g.12xlarge    r6g.medium  a1.medium   m6g.xlarge  m6gd.4xlarge    t4g.nano    r6g.16xlarge
t4g.2xlarge m6g.12xlarge    r6gd.8xlarge    a1.large    m6g.4xlarge c6gd.16xlarge   t4g.xlarge  c6g.large   m6g.large   c6gd.xlarge a1.metal    m6g.8xlarge m6gd.16xlarge   a1.xlarge   r6g.12xlarge    r6gd.metal  t4g.micro   r6g.4xlarge t4g.small   a1.2xlarge  r6gd.4xlarge    t4g.large
m6g.16xlarge    c6g.4xlarge m6gd.2xlarge    c6gd.medium c6gd.8xlarge    r6gd.16xlarge   m6gd.8xlarge    c6g.2xlarge r6gd.12xlarge   a1.4xlarge  c6g.8xlarge r6g.2xlarge m6g.2xlarge m6g.medium  c6gd.large  c6g.medium  c6gd.2xlarge    r6g.metal   c6gd.4xlarge    m6gd.large  r6g.xlarge

我在TF中没有看到相应的功能。最糟糕的情况是,您可以为此定义external数据源。

更新

无法通过单个调用以AMI为基础获取实例类型列表,必须分两步完成。

  1. 使用aws_ami数据源获取给定AMI的架构信息
  2. 使用describe-instance-types获取该架构的实例类型。

我在想是否有一种方法可以找出给定AMI ID的信息。 - Rpj
@Rpj 我知道了。让我查一下。 - Marcin
aws_ec2_instance_type_offerings 是 AWS 提供商的等效于 describe-instance-types 命令吗?我对两者都不熟悉,但数据源似乎具有与您在此处展示的命令相似的输入和输出。 - Martin Atkins
@MartinAtkins,它是独立的API DescribeInstanceTypeOfferings。您无法通过支持的CPU架构进行过滤。 - Marcin
啊,我明白了。对于造成的困惑感到抱歉!“返回所有提供的实例类型列表”和“描述在位置提供的实例类型的详细信息”听起来对我来说是一样的,但我想它们在基础数据模型中有所不同。‍♂ - Martin Atkins

0

我发现this篇文章很有用,因为它解释了如果你正在使用新的实例类型(例如t4g),它将使用ARM64架构而不是默认的x86_64。因此,您需要指定要使用ARM64的机器映像。

我举的例子是我正在创建的Bastion Host(Python):

self.bastion = ec2.BastionHostLinux(
        self,
        "BastionHostEC2",
        vpc=vpc,
        instance_name=f"{deployment_name} - Bastion Host",
        instance_type=ec2.InstanceType("t4g.micro"),
        machine_image=ec2.AmazonLinuxImage(cpu_type=ec2.AmazonLinuxCpuType.ARM_64),
    )

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接