<?php

# Simple configuration;
$OLD_CERTIFICATE = 'old-certificate-name';
$NEW_CERTIFICATE = 'new-certificate-name';
require '/usr/share/php/AWSSDKforPHP/sdk.class.php';
$ec2 = new AmazonEC2();
$elb = new AmazonELB();
$iam = new AmazonIAM();
$response = $iam->get_server_certificate($NEW_CERTIFICATE);
$response_available_regions = $ec2->describe_regions();
$available_regions = array(AmazonELB::REGION_US_E1, AmazonELB::REGION_US_W1, AmazonELB::REGION_EU_W1, AmazonELB::REGION_APAC_SE1, AmazonELB::REGION_APAC_SE2, AmazonELB::REGION_APAC_NE1, AmazonELB::REGION_SA_E1);
foreach ($available_regions as $region) {
    $elb->set_region($region);
    $list_of_elbs = $elb->describe_load_balancers();
    $elbs = $list_of_elbs->body->to_stdClass();
    foreach ($elbs->DescribeLoadBalancersResult->LoadBalancerDescriptions->member as $single_elb) {
        echo $single_elb->LoadBalancerName . "\n";
        foreach ($single_elb->ListenerDescriptions->member as $single_listener) {
            if ($single_listener->SSLCertificateId != "") {
                $pos = strpos($single_listener->SSLCertificateId, $OLD_CERTIFICATE);
                if ($pos === false) {
                    echo "\t- No need to replace: " . $single_listener->SSLCertificateId . "\n";
                } else {
                    echo "\t- Replacing certificate for port " . $single_listener->LoadBalancerPort . "...";
                    $elb->set_load_balancer_listener_ssl_certificate($single_elb->LoadBalancerName, $single_listener->LoadBalancerPort, $response->body->GetServerCertificateResult->ServerCertificate->ServerCertificateMetadata->Arn);
                    echo " Done!\n";
                }
            }
        }
    }
コード例 #2
0
ファイル: ec2.inc.php プロジェクト: ceeaspb/webpagetest
function EC2_GetRunningInstances()
{
    $now = time();
    $instances = array();
    $key = GetSetting('ec2_key');
    $secret = GetSetting('ec2_secret');
    if ($key && $secret) {
        $ec2 = new AmazonEC2($key, $secret);
        $regions = array();
        $response = $ec2->describe_regions();
        if (isset($response) && $response->isOK()) {
            foreach ($response->body->regionInfo->item as $region) {
                $regions[] = (string) $region->regionName;
            }
        }
        foreach ($regions as $region) {
            $ec2->set_region($region);
            $response = $ec2->describe_instances();
            if (isset($response) && $response->isOK()) {
                foreach ($response->body->reservationSet->item as $item) {
                    foreach ($item->instancesSet->item as $instance) {
                        $wptLocations = null;
                        if (isset($instance->tagSet)) {
                            foreach ($instance->tagSet->item as $tag) {
                                if ($tag->key == 'WPTLocations') {
                                    $wptLocations = explode(',', $tag->value);
                                    break;
                                }
                            }
                        }
                        if (isset($wptLocations)) {
                            $launchTime = strtotime((string) $instance->launchTime);
                            $elapsed = $now - $launchTime;
                            $instances[] = array('region' => $region, 'id' => (string) $instance->instanceId, 'ami' => (string) $instance->imageId, 'state' => (int) $instance->instanceState->code, 'launchTime' => (string) $instance->launchTime, 'launched' => $launchTime, 'runningTime' => $elapsed, 'locations' => $wptLocations);
                        }
                    }
                }
            }
        }
    }
    // update the AMI counts we are tracking locally
    if (count($instances)) {
        $lock = Lock('ec2-instances', true, 120);
        if ($lock) {
            $amis = array();
            foreach ($instances as $instance) {
                if (isset($instance['ami']) && strlen($instance['ami']) && is_numeric($instance['state']) && $instance['state'] <= 16) {
                    if (!isset($amis[$instance['ami']])) {
                        $amis[$instance['ami']] = array('count' => 0);
                    }
                    $amis[$instance['ami']]['count']++;
                }
            }
            file_put_contents('./tmp/ec2-instances.dat', json_encode($amis));
            Unlock($lock);
        }
    }
    return $instances;
}