Ejemplo n.º 1
0
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;
$res1 = $ec2->create_volume($availabilityZone, $opt);
$res2 = $ec2->create_volume($availabilityZone, $opt);
if (!$res1->isOK() || !$res2->isOK()) {
    exit("Could not create EBS volumes.\n");
}
// Get the volume Ids
$volumeId1 = (string) $res1->body->volumeId;
$volumeId2 = (string) $res2->body->volumeId;
print "Created EBS volumes {$volumeId1} and {$volumeId2}.\n";
// Attach the volumes to the instance as /dev/sdf and /dev/sdg
$res1 = $ec2->attach_volume($volumeId1, $instanceId, '/dev/sdf');
$res2 = $ec2->attach_volume($volumeId2, $instanceId, '/dev/sdg');
if (!$res1->isOK() || !$res2->isOK()) {
    exit("Could not attach EBS volumes " . "{$volumeId1} and {$volumeId2} " . "to instance {$instanceId}.\n");
}
print "Attached EBS volumes {$volumeId1} and {$volumeId2} " . "to instance {$instanceId}.\n";