2013-12-16 241 views
4

我想并行启动多个EC2计算机。到目前为止,我使用boto和结构,但串行执行需要很长时间才能启动并逐一提供。任何替代解决方案/工具来做到这一点?并行启动多个EC2实例

回答

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. 

更新:根据博托EC2文档,可以在min_count和MAX_COUNT参数的run_instances指挥通行,这也将让你并行启动多个实例。

+0

上面的信息没有提及任何地方是否创建“同时”或“一个接一个”的多个实例。 OP正在寻找替代多个实例启动的“串行执行”。 – slayedbylucifer

+0

@slayedbylucifer:这是一个单一的命令,实例是并行创建的。 – chris

+0

同意。刚刚尝试过,它工作。尝试与Ruby SDK以及它的工作。它们都在并行创建实例,因为它们都调用相同的API。不知道为什么OP说python boto不是并行创建实例。我从来没有试过博托。但AWS CLI在窗帘后面使用boto。 – slayedbylucifer

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" 
     }   
} 

您可以boto或通过使用CLI

BTW-由于您向AWS服务发送单个请求,因此性能更好,即汉作为一个堆栈而溺爱。终止实例(以及任何其他您想添加的资源)只需删除堆栈。