我想并行启动一些EC2机器。到目前为止,我使用的是boto和fabric,但是串行执行需要很长时间才能启动并逐个配置它们。任何替代解决方案/工具吗?
答案 0 :(得分:2)
amazon命令行工具支持实例数量的参数。
aws ec2 run-instances help
--count (string)
Number of instances to launch. If a single number is provided, it is
assumed to be the minimum to launch (defaults to 1). If a range is
provided in the form min:max then the first number is interpreted as
the minimum number of instances to launch and the second is inter-
preted as the maximum number of instances to launch.
如果您正在运行较旧的CLI:
ec2-run-instances
-n, --instance-count MIN[-MAX]
The number of instances to attempt to launch. May be specified as a
single integer or as a range (min-max). This specifies the minimum
and maximum number of instances to attempt to launch. If a single
integer is specified min and max are both set to that value.
更新:根据boto ec2文档,您可以将min_count和max_count参数传递给run_instances命令,这也可以让您并行启动多个实例。
答案 1 :(得分:1)
您可以使用CloudFormation启动固定大小的自动缩放组:
"MyFixedSizeGroup":{
"Type":"AWS::AutoScaling::AutoScalingGroup",
"Properties":{
"LaunchConfigurationName":{"Ref":"GlobalWorkersSmallLaunchConf"},
"AvailabilityZones" : [ "us-east-1a" ],
"MinSize":"4",
"MaxSize":"4",
"DesiredCapacity":"4",
"Tags":[{"Key":"Name", "Value":"worker instance", "PropagateAtLaunch":"true"}]
}
}
和所需的启动配置,例如:
"GlobalWorkersSmallLaunchConf":{
"Type":"AWS::AutoScaling::LaunchConfiguration",
"Properties":{"KeyName":{"Ref":"MyKeyName"},
"ImageId":"ami-SomeAmi",
"UserData":{"Fn::Base64":{"Fn::Join":["",[{"Ref":"SomeInitScript"}]]}},
"SecurityGroups":[{"Ref":"InstanceSecurityGroup"}],
"InstanceType":"m1.small",
"InstanceMonitoring":"false"
}
}
一起使用
BTW-它执行得更好,因为您向AWS服务发送了一个请求,该请求作为堆栈处理。终止实例(以及您要添加的任何其他资源)只需删除堆栈。