Last active
December 29, 2015 12:49
-
-
Save raananraz/7672952 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 | |
define("AWS_KEY","YOUR KEY"); | |
define("AWS_SECRET","YOUR SECRET KEY"); | |
define("AWS_REGION","REGION OF THE LOAD BALANCER"); | |
define("ELB_NAME","YOUR ELB NAME"); | |
define("INSTANCE_ID","CURRENT INSTANCE ID - TO BE EXLUCDED FROM THE TEST"); | |
//no cache headers | |
header("Expires: 0"); | |
header("Cache-Control: no-store, no-cache, must-revalidate"); | |
header("Pragma: no-cache"); | |
require 'AWSSDKforPHP/aws.phar'; | |
use Aws\ElasticLoadBalancing\ElasticLoadBalancingClient; | |
$client = ElasticLoadBalancingClient::factory(array( | |
'key' => AWS_KEY, | |
'secret' => AWS_SECRET, | |
'region' => AWS_REGION | |
)); | |
print "Checking =>".ELB_NAME."(".AWS_REGION.")<br>"; | |
foreach($result["InstanceStates"] as $instance){ | |
print $instance["InstanceId"]."-".$instance["State"]."<br>"; | |
if($instance["InstanceId"] != INSTANCE_ID && $instance["State"] == "InService"){ | |
header("HTTP/1.1 500 Internal Server Error"); | |
die("At least one server is UP"); | |
} | |
} | |
die("Servers are down - show down error"); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment