/**
  * @covers Aws\AutoScaling\AutoScalingClient::factory
  */
 public function testFactoryInitializesClient()
 {
     $client = AutoScalingClient::factory(array('key' => 'foo', 'secret' => 'bar', 'region' => 'us-west-2'));
     $this->assertInstanceOf('Aws\\Common\\Signature\\SignatureV4', $client->getSignature());
     $this->assertInstanceOf('Aws\\Common\\Credentials\\Credentials', $client->getCredentials());
     $this->assertEquals('https://autoscaling.us-west-2.amazonaws.com', $client->getBaseUrl());
 }
Esempio n. 2
0
 function __construct($region, $autoScalingGroupName)
 {
     if (!class_exists('\\Aws\\AutoScaling\\AutoScalingClient')) {
         throw new AWSClientException("Please install the AWS SDK in order to use the AWS autoscaling functionality of JQJobs.");
     }
     if (!getenv("AWS_ACCESS_KEY_ID") || !getenv("AWS_SECRET_ACCESS_KEY")) {
         throw new AWSClientException("AWS credentials not found. Please set environment variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.");
     }
     $autoScalingSettings = array('region' => $region);
     $this->autoScalingClient = \Aws\AutoScaling\AutoScalingClient::factory($autoScalingSettings);
     $this->autoScalingGroupName = $autoScalingGroupName;
 }
Esempio n. 3
0
 /**
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->client = AutoScalingClient::factory($this->getConfig());
 }
<?php

require_once 'aws-autoloader.php';
require_once 'config.php';
use Aws\AutoScaling\AutoScalingClient;
use Aws\Ec2\Ec2Client;
# Downloads the latest from remote without trying to merge or rebase anything
# Resets the master branch to what you just fetched
if (isset($_POST['deploy']) and $_POST['deploy'] == 1) {
    exec('cd ' . $doc_root . ' && git fetch --all && git reset --hard origin/master');
} elseif (isset($argc) and $argc == 2 and $argv[1] == 'update') {
    exec('cd ' . $doc_root . ' && git fetch --all && git reset --hard origin/master');
} elseif (isset($_REQUEST['payload'])) {
    # Create a autoscaling client object
    $as_client = AutoScalingClient::factory(array('key' => $access_key, 'secret' => $secret_key, 'region' => $region));
    # Create a ec2 client object
    $ec2_client = Ec2Client::factory(array('key' => $access_key, 'secret' => $secret_key, 'region' => $region));
    # EC2 instance id
    $ec2_id = array();
    # This includes all Amazon EC2 instances that are members of the group
    $result = $as_client->describeAutoScalingGroups(array('AutoScalingGroupNames' => array($as_group)));
    $result = $result['AutoScalingGroups'];
    foreach ($result as $value) {
        $instance = $value['Instances'];
        # Append ec2 instance id
        foreach ($instance as $id) {
            array_push($ec2_id, $id['InstanceId']);
        }
    }
    # This includes all information about instance id in $ec2_id which are currently running
    $result = $ec2_client->describeInstances(array('InstanceIds' => $ec2_id, 'Filters' => array(array('Name' => 'instance-state-name', 'Values' => array('running')))));
 /**
  * Instantiates a new AutoScaling Client
  *
  * @return AutoScalingClient
  */
 protected function getClient()
 {
     $credentials = $this->getCredentials();
     $client = AutoScalingClient::factory(array('key' => $credentials['aws_api_key'], 'secret' => $credentials['aws_api_secret'], 'region' => $credentials['aws_region']));
     return $client;
 }