2013-12-16 240 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服務發送單個請求,因此性能更好,即漢作爲一個堆棧而溺愛。終止實例(以及任何其他您想添加的資源)只需刪除堆棧。