如果应用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?
发布于 2018-05-20 10:51:45
您可以在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.
发布于 2018-05-23 18:53:15
地面形式的自动柜员机不可能获得现货车队的实例。
您需要在AWS SDK / boto3中编写代码来查找使用Spot队列创建的实例。EC2 AutoScaling组和EMR集群也是如此。
谢谢。
https://stackoverflow.com/questions/50427287
复制相似问题