Ejemplo n.º 1
0
function EC2_LaunchInstance($region, $ami, $size, $user_data, $loc)
{
    $ret = false;
    $key = GetSetting('ec2_key');
    $secret = GetSetting('ec2_secret');
    if ($key && $secret) {
        $ec2 = new AmazonEC2($key, $secret);
        $ec2->set_region($region);
        $response = $ec2->run_instances($ami, 1, 1, array('InstanceType' => $size, 'UserData' => base64_encode($user_data)));
        if ($response->isOK()) {
            $ret = true;
            if (isset($loc) && strlen($loc) && isset($response->body->instancesSet->item->instanceId)) {
                $instance_id = (string) $response->body->instancesSet->item->instanceId;
                $ec2->create_tags($instance_id, array(array('Key' => 'Name', 'Value' => 'WebPagetest Agent'), array('Key' => 'WPTLocations', 'Value' => $loc)));
            }
        }
    }
    return $ret;
}
Ejemplo n.º 2
0
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
// Create the EC2 access object
$ec2 = new AmazonEC2();
// Run an instance
$options = array('KeyName' => "testkey", 'InstanceType' => "m1.small");
$res = $ec2->run_instances("ami-48aa4921", 1, 1, $options);
if (!$res->isOK()) {
    exit("Could not launch instance: " . $res->body->Errors->Error->Message . "\n");
}
// Get the Id and Availability Zone of the instance
$instances = $res->body->instancesSet;
$instanceId = (string) $instances->item->instanceId;
$availabilityZone = (string) $instances->item->placement->availabilityZone;
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;
Ejemplo n.º 3
0
 *
 * or in the "license.txt" file accompanying this file. This file is
 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
 * OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the
 * License.
 *
 * Modified by Jeffrey S. Haemer <*****@*****.**>
 */
error_reporting(E_ALL);
require_once 'AWSSDKforPHP/sdk.class.php';
// Create the EC2 access object
$ec2 = new AmazonEC2();
// Run an instance
$options = array('KeyName' => "testkey", 'InstanceType' => "t1.micro", 'Placement.AvailabilityZone' => "us-east-1a");
$res = $ec2->run_instances("ami-08728661", 1, 1, $options);
if (!$res->isOK()) {
    exit("Could not launch instance: " . $res->body->Errors->Error->Message . "\n");
}
// Get the Id and Availability Zone of the instance
$instances = $res->body->instancesSet;
$instanceId = (string) $instances->item->instanceId;
$availabilityZone = (string) $instances->item->placement->availabilityZone;
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;