public function findAutoScalingGroups() { $result = $this->asgClient->describeAutoScalingGroups(); $rows = $result->search('AutoScalingGroups[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $collection->attach(new AutoScalingGroup($row)); } return $collection; }
/** * @return \AwsInspector\Model\Collection */ public function findLaunchConfigurations() { $result = $this->asgClient->describeLaunchConfigurations(); $rows = $result->search('LaunchConfigurations[]'); $collection = new \AwsInspector\Model\Collection(); foreach ($rows as $row) { $collection->attach(new LaunchConfiguration($row)); } return $collection; }
/** * @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()); }
private function initAutoscaleGroups() { $asClient = new \Aws\AutoScaling\AutoScalingClient(['version' => 'latest', 'region' => 'us-east-1', 'credentials' => new \Aws\Credentials\Credentials($this->creds->getKey(), $this->creds->getSecret())]); //Download the contents of the object. $result = $asClient->describeAutoScalingGroups(['AutoScalingGroupNames' => [], 'MaxRecords' => 99]); //echo(var_dump($result)); //exit; foreach ($result['AutoScalingGroups'] as $asGroup) { $as = new \Kyrio\AWS\EC2\AutoscaleGroup(); $as->init($this->creds); $as->load($this->creds, $asGroup); $as->setArn($asGroup['AutoScalingGroupARN']); $this->elbCount += count($as->getLoadBalancers()); $this->autoscaleGroups[$asGroup['AutoScalingGroupARN']] = $as; } return true; }
public function testBasicOperations() { $launchConfigName = 'php-integ-as-launch-config'; self::log('Create a launch configuration.'); $this->autoscaling->createLaunchConfiguration(array('LaunchConfigurationName' => $launchConfigName, 'ImageId' => self::TEST_AMI, 'InstanceType' => InstanceType::M1_SMALL)); self::log('Make sure error handling works by trying to recreate the same launch configuration.'); try { $this->autoscaling->createLaunchConfiguration(array('LaunchConfigurationName' => $launchConfigName, 'ImageId' => self::TEST_AMI, 'InstanceType' => InstanceType::M1_SMALL)); $this->fail('An exception should have been thrown'); } catch (AlreadyExistsException $e) { $this->assertInstanceOf('Aws\\AutoScaling\\Exception\\AlreadyExistsException', $e); } self::log('Make sure iterators work by iterating launch configurations.'); $launchConfigs = $this->autoscaling->getIterator('DescribeLaunchConfigurations')->toArray(); $this->assertGreaterThanOrEqual(1, count($launchConfigs)); $this->assertArrayHasKey('LaunchConfigurationName', $launchConfigs[0]); self::log('Delete the launch configuration.'); $this->autoscaling->deleteLaunchConfiguration(array('LaunchConfigurationName' => $launchConfigName)); }
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; }
/** * @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; }