コード例 #1
0
ファイル: ec2.inc.php プロジェクト: ceeaspb/webpagetest
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;
}
コード例 #2
0
ファイル: ec2_setup.php プロジェクト: jsh/BarrBookCode
 *
 * 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;
コード例 #3
0
ファイル: launch_ec2_micro.php プロジェクト: jsh/BarrBookCode
 *
 * 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;