// Enable full-blown error reporting. http://twitter.com/rasmus/status/7448448829
error_reporting(-1);
// Set HTML headers
header("Content-type: text/html; charset=utf-8");
// Include the SDK
require_once '../sdk.class.php';
/*%******************************************************************************************%*/
// THE GOALS & PREPARATION
/*
	1. The goal of this exercise is to retrieve a list of all image IDs that are prefixed with "aki-".
	2. We should end up with an indexed array of string values (just the image IDs).
*/
// Instantiate the AmazonEC2 class
$ec2 = new AmazonEC2();
// Get the response from a call to the DescribeImages operation.
$response = $ec2->describe_images();
/*%******************************************************************************************%*/
// THE LONG WAY
// Prepare to collect AKIs.
$akis = array();
// Loop through the response...
foreach ($response->body->imagesSet->item as $item) {
    // Stringify the value
    $image_id = (string) $item->imageId;
    // Filter the value against a PCRE regular expression.
    if (preg_match('/aki/i', $image_id)) {
        // If the name matches our pattern, add it to the list.
        $akis[] = $image_id;
    }
}
// Display