如果适用Terraform,请将6个EC2实例作为目标容量,如example所示:
# Request a Spot fleet
resource "aws_spot_fleet_request" "cheap_compute" {
iam_fleet_role = "arn:aws:iam::12345678:role/spot-fleet"
spot_price = "0.03"
allocation_strategy = "diversified"
target_capacity = 6
valid_until = "2019-11-04T20:44:20Z"
launch_specification {
instance_type = "m4.10xlarge"
ami = "ami-1234"
spot_price = "2.793"
placement_tenancy = "dedicated"
iam_instance_profile_arn = "${aws_iam_instance_profile.example.arn}"
}
launch_specification {
instance_type = "m4.4xlarge"
ami = "ami-5678"
key_name = "my-key"
spot_price = "1.117"
iam_instance_profile_arn = "${aws_iam_instance_profile.example.arn}"
availability_zone = "us-west-1a"
subnet_id = "subnet-1234"
weighted_capacity = 35
root_block_device {
volume_size = "300"
volume_type = "gp2"
}
tags {
Name = "spot-fleet-example"
}
}
}
唯一可用的属性是'id'和'spot_request_state'。
如何输出已启动实例的私有IP地址?
这是可能的,还是我需要使用像Boto3这样的其他工具?
答案 0 :(得分:0)
您可以在Terraform中使用Data Sources
。这些允许您实质上执行API调用以从AWS检索数据。创建资源后,您可以使用以下Terraform -
data "aws_instances" "spot-fleet-ips" {
instance_tags {
Name = "spot-fleet-example"
}
}
要获取IP,您可以执行以下操作 -
"${data.aws_instances.spot-fleet-ips.private_ips}"
上述数据来源的文档为here.
答案 1 :(得分:0)
地形中的atm不可能获得Spot舰队的实例。
您需要在AWS SDK / boto3中编写代码才能找到使用竞价型队列创建的实例。对于EC2 AutoScaling Groups& amp; EMR集群。
感谢。