Skip to content

Instantly share code, notes, and snippets.

@chregu
Created November 24, 2010 15:53
Show Gist options
  • Save chregu/713856 to your computer and use it in GitHub Desktop.
Save chregu/713856 to your computer and use it in GitHub Desktop.
<?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