Retry the AWS API when looking for a newly created instance

Sometimes the AWS API responds that it can't find a newly created
instance if you poll it too soon after creation.  Retry a few times
to be sure it really hasn't been created.
This commit is contained in:
lokulin 2015-05-22 15:08:51 +10:00
parent 350a5f8cad
commit bda4ef7c65
1 changed files with 10 additions and 1 deletions

View File

@ -195,7 +195,16 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
instanceId = spotResp.SpotRequestResults[0].InstanceId
}
instanceResp, err := ec2conn.Instances([]string{instanceId}, nil)
var instanceResp, instanceErr = ec2conn.Instances([]string{instanceId}, nil)
for i := 0; i < 10; i++ {
if instanceErr == nil {
err = instanceErr
break
}
time.Sleep(time.Duration(3))
instanceResp, err = ec2conn.Instances([]string{instanceId}, nil)
}
if err != nil {
err := fmt.Errorf("Error finding source instance (%s): %s", instanceId, err)
state.Put("error", err)