예제 #1
0
print "Launched instance {$instanceId} " . "in availability zone {$availabilityZone}.\n";
// Wait for the instance's state to change to running
// before attaching volumes
do {
    $options = array('InstanceId.1' => $instanceId);
    $res = $ec2->describe_instances($options);
    $instances = $res->body->reservationSet->item->instancesSet;
    $state = $instances->item->instanceState->name;
    $running = $state == 'running';
    if (!$running) {
        print "Instance is currently in " . "state {$state}, waiting 10 seconds\n";
        sleep(10);
    }
} while (!$running);
// Allocate an Elastic IP address
$res = $ec2->allocate_address();
if (!$res->isOK()) {
    exit("Could not allocate public IP address.\n");
}
// Get the allocated Elastic IP address
$publicIP = (string) $res->body->publicIp;
print "Assigned IP address {$publicIP}.\n";
// Associate the Elastic IP address with the instance
$res = $ec2->associate_address($instanceId, $publicIP);
if (!$res->IsOK()) {
    exit("Could not associate IP address {$publicIP} " . "with instance {$instanceId}.\n");
}
print "Associated IP address {$publicIP} " . "with instance {$instanceId}.\n";
// Create two EBS volumes in the instance's availability zone
$opt = array();
$opt['Size'] = 1;