示例#1
0
 public function init($creds)
 {
     $ec2Client = new \Aws\Ec2\Ec2Client(['version' => 'latest', 'region' => 'us-east-1', 'credentials' => new \Aws\Credentials\Credentials($creds->getKey(), $creds->getSecret())]);
     $result = $ec2Client->describeInstances(['InstanceIds' => [$this->instanceID], 'DryRun' => false]);
     $instance = $result['Reservations'][0]['Instances'][0];
     $this->launchTime = $instance['LaunchTime'];
     $this->keyName = $instance['KeyName'];
     return true;
 }
示例#2
0
require "credentials.php";
$ec2 = new Aws\Ec2\Ec2Client($credentials);
$command = filter_input(INPUT_POST, "command", FILTER_SANITIZE_STRING);
$ids = filter_input(INPUT_POST, "ids", FILTER_SANITIZE_STRING, FILTER_REQUIRE_ARRAY);
$error = null;
if ($command === "Start") {
    try {
        $result = $ec2->startInstances(["InstanceIds" => $ids]);
    } catch (Ec2Exception $e) {
        $error = $e->getMessage();
        exit($error);
    }
    echo $result;
}
if ($command === "Stop") {
    try {
        $result = $ec2->stopInstances(["InstanceIds" => $ids]);
    } catch (Ec2Exception $e) {
        $error = $e->getMessage();
        exit($error);
    }
}
#$ids = ["i-8992db20"];
try {
    $result = $ec2->describeInstances(["InstanceIds" => $ids]);
} catch (Ec2Exception $e) {
    $error = $e->getMessage();
    exit($error);
}
#echo json_encode($result->search("Reservations[*].Instances[*]"), JSON_PRETTY_PRINT);
echo json_encode($result->search("Reservations[*].Instances[*].{InstanceId:InstanceId,State:State.Name}"), JSON_PRETTY_PRINT);
示例#3
0
<?php

require 'vendor/autoload.php';
#	use Aws\Common\Aws;
$tag = 'architecture';
$values = array('i386', 'x86_64');
$client = new Aws\Ec2\Ec2Client(array('region' => 'us-west-2', 'debug' => false, 'version' => 'latest', 'profile' => 'default'));
$owner = "B.Gates";
$param = array('Filters' => array(array('Name' => $tag, 'Values' => $values), array('Name' => 'tag:Name', 'Values' => array('EU *')), array('Name' => 'tag:Owners', 'Values' => array($owner, $owner . ",*", "*," . $owner . ",*", "*," . $owner))));
$result = $client->describeInstances($param);
foreach ($result['Reservations'] as $reservation) {
    foreach ($reservation['Instances'] as $instance) {
        foreach ($instance['Tags'] as $instanceTag) {
            $instanceName = '';
            if ($instanceTag['Key'] == 'Name') {
                $instanceName = $instanceTag['Value'];
            }
        }
        print "Instance Name: " . $instanceName . "\n";
        print "Instance ID: " . $instance['InstanceId'] . "\n";
        print "----> State: " . $instance['State']['Name'] . "\n";
        print "----> Instance Type: " . $instance['InstanceType'] . "\n";
        foreach ($instance['NetworkInterfaces'] as $networkinterface) {
            print "----> Network InterfaceId: " . $networkinterface['NetworkInterfaceId'] . "\n";
            print "----> Network Interface MAC Address: " . $networkinterface['macAddress'] . "\n";
            $num_ipaddress = sizeof($networkinterface['PrivateIpAddresses']) . "\n";
            for ($i = 0; $i < $num_ipaddress; $i++) {
                if ($i == 0) {
                    print "----> Network Interface Primary Private Ip Address: ";
                } else {
                    print "----> Instance Other Private Address: ";