使用了ap-south-1
区域http://cloud-images.ubuntu.com/locator/ec2/
中的ami-0fd3c3c68a2a8066f
,但无法对此使用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的适用实例类型列表
使用AWS CLI可以使用描述实例类型:
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中没有看到任何类似的东西。在最坏的情况下,您可以为此定义外部数据源。
更新
没有单个调用来获取基于ami的实例类型列表。这必须分两步来完成。
- 使用aws_ami数据源获取给定ami的体系结构
- 使用描述实例类型来获取该体系结构的实例类型
我发现这篇文章很有用,因为它解释说,如果您使用一种新的实例类型,如t4g,它将使用ARM64体系结构,而不是默认的x86_64。因此,您需要指定要使用ARM64的机器映像。
我的例子是我正在创建的堡垒主机(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),
)