Skip to content

Instantly share code, notes, and snippets.

@scumola
Created January 20, 2012 23:38
Show Gist options
  • Save scumola/1650258 to your computer and use it in GitHub Desktop.
Save scumola/1650258 to your computer and use it in GitHub Desktop.
aws php sdk list all instances in all regions
<?php
error_reporting(0);
header("Content-type: text/html; charset=utf-8");
require_once '../sdk.class.php';
$ec2 = new AmazonEC2();
$response = $ec2->describe_regions();
foreach ($response->body->regionInfo->item as $item) {
$region_endpoint = (string) $item->regionEndpoint;
$region_name = (string) $item->regionName;
$ec2->set_hostname($region_endpoint);
$response2 = $ec2->describe_instances();
foreach ($response2->body->reservationSet->item as $item) {
$instanceId = (string) $item->instancesSet->item->instanceId;
$privateIpAddress = (string) $item->instancesSet->item->privateIpAddress;
$ipAddress = (string) $item->instancesSet->item->ipAddress;
$instanceType = (string) $item->instancesSet->item->instanceType;
$architecture = (string) $item->instancesSet->item->architecture;
$tag_machine_type = $tag_deployment = $tag_name = "";
foreach ($item->instancesSet->item->tagSet->item as $tags) {
if ($tags->key == "MachineType") {
$tag_machine_type = (string) $tags->value;
}
if ($tags->key == "Deployment") {
$tag_deployment = (string) $tags->value;
}
if ($tags->key == "Name") {
$tag_name = (string) $tags->value;
}
}
print ("$instanceId|$region_name|$tag_name|$tag_deployment|$tag_machine_type|$privateIpAddress|$ipAddress|$instanceType|$architecture\n");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment