I want to create an ec2 instance, and use the "Waiter" functionality to wait until the Instance has a Public DNS Name - is this possible?
Here is my code:
$ec2 = new Aws\Ec2\Ec2Client([credentials]);
$result = $ec2->runInstances(array(
'DryRun' => false,
// ImageId is required
'ImageId' => '[removed]',
// MinCount is required
'MinCount' => 1,
// MaxCount is required
'MaxCount' => 1,
'KeyName' => '[removed]',
'SecurityGroupIds' => array('[removed]'),
'InstanceType' => 'r3.4xlarge',
'Placement' => array(
'AvailabilityZone' => 'us-east-1a',
),
'EbsOptimized' => false,
'Monitoring' => array(
// Enabled is required
'Enabled' => true,
),
));
$arr = $result->toArray();
$instanceId = $arr['Instances'][0]['InstanceId'];
echo 'created instance '.$instanceId."\n";
$ec2->waitUntil('InstanceRunning', ['InstanceIds' => array($instanceId)]);
$result = $ec2->describeInstances(array(
'InstanceIds' => array($instanceId),
));
$dnsName = current($result->getPath('Reservations/*/Instances/*/PublicDnsName'));
The instance is created just fine but the last line fails, because the instance does not have a public dns name because an instance is considered 'running' before it has a dns name. Is there a waiter I can use to wait until it has a dns name?
Here are the waiters: http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-04-15.html#waiters