Created
November 24, 2010 15:53
-
-
Save chregu/713856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require_once 'AWSSDKforPHP/sdk.class.php'; | |
// Instantiate the AmazonEC2 class | |
$ec2 = new AmazonEC2(); | |
$ec2->set_region(AmazonEC2::REGION_EU_W1); | |
$resp = $ec2->describe_instances(); | |
$countInst = count($resp->body->reservationSet->item); | |
$elb = new AmazonELB(); | |
$elb->set_region(AmazonELB::REGION_EU_W1); | |
$resp = $ec2->run_instances("ami-f5facf81",1,1, | |
array("KeyName" => "chregu", | |
"InstanceType" => "t1.micro", | |
"Placement.AvailabilityZone" => "eu-west-1a", | |
"Monitoring.Enabled" => true, | |
"UserData" => base64_encode($userData), | |
) | |
); | |
if (!$resp->isOK()) { | |
var_dump($resp); | |
print "ERRRRORRRR\n"; | |
die(); | |
} | |
$ec3 = new AmazonEC2(); | |
$ec3->set_region(AmazonEC2::REGION_EU_W1); | |
foreach ($resp->body->instancesSet->item as $item) { | |
$id = (string) $item->instanceId; | |
print $id. " started \n"; | |
$resp = $ec3->create_tags((string) $item->instanceId, array( | |
array("Key" => "Name", "Value" => "$lbName ". $countInst), | |
array("Key" => "Liip Autostart", "Value" => "yes") | |
) | |
); | |
if ($lbName) { | |
print "trying to add to LB $lbName\n"; | |
$response = $elb->register_instances_with_load_balancer($lbName, array( | |
array('InstanceId' => $id), | |
)); | |
if ($response->isOK()) { | |
print " added to $lbName loadbalancer\n"; | |
} else { | |
var_dump($response); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment