-
-
Save erikh/1c393c51784a6f684b8f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from the docs -- | |
# returns an Array on multiple servers and a | |
# AWS::EC2::Instance for a single server. | |
instances = aws_ec2.instances.create( | |
:count => @number_of_servers, | |
:image_id => ec2.ami, | |
:security_groups => ec2.security_groups, | |
:key_name => ec2.ssh_key | |
) | |
p instances.class # Actually an AWS::Core::Data::List in the multiple case | |
# box it if it's not an array. AWS::Core::Data::List is a kind of Array. | |
instances = [instances] unless instances.kind_of?(Array) | |
# | |
# There are instances where AWS won't acknowledge a created instance | |
# right away. Let's make sure the API server knows they all exist before | |
# moving forward. | |
# | |
unresolved_instances = instances.dup # Returns new Array for Array, returns self for AWS::Core::Data::List | |
until unresolved_instances.empty? | |
instance = unresolved_instances.shift | |
unless (instance.status rescue nil) | |
if_debug(3) do | |
$stderr.puts "API server doesn't think #{instance.id} exists yet." | |
end | |
sleep 0.3 | |
unresolved_instances.push(instance) | |
end | |
end | |
p instances # empty for AWS::Core::Data::List | |
# by my best calculation this bug cost the company around $150 to find, and that's long before my salary comes into play. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment