amazon web services - AWS EC2 with PHP SDK - wait until instance has Public DNS Name -


i want create ec2 instance, , use "waiter" functionality wait until instance has public dns name - possible?

here code:

$ec2 = new aws\ec2\ec2client([credentials]);  $result = $ec2->runinstances(array(                 'dryrun' => false,                 // imageid required                 'imageid' => '[removed]',                 // mincount required                 'mincount' => 1,                 // maxcount required                 'maxcount' => 1,                 'keyname' => '[removed]',                 'securitygroupids' => array('[removed]'),                  'instancetype' => 'r3.4xlarge',                  'placement' => array(                     'availabilityzone' => 'us-east-1a',                  ),                 'ebsoptimized' => false,                 'monitoring' => array(                     // enabled 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 created fine last line fails, because instance not have public dns name because instance considered 'running' before has dns name. there waiter can use wait until has dns name?

here waiters: http://docs.aws.amazon.com/aws-sdk-php/v3/api/api-ec2-2015-04-15.html#waiters

there no waiter function public dns name. 2 options can think of:

1.) use sleep or sort of while loop / sleep method until can publicdnsname. kind of hacky , blocks thread.

2.) more elegant way make whole thing asynchronous using queuing, or php implementation of asynchronous.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -