PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Amazon Instance Utilities

In this section you will find out how to retreive information, the console output and see if an instance contains a product code.

Example 722. Describing Instances

describe returns information about instances that you own.

If you specify one or more instance IDs, Amazon EC2 returns information for those instances. If you do not specify instance IDs, Amazon EC2 returns information for all relevant instances. If you specify an invalid instance ID, a fault is returned. If you specify an instance that you do not own, it will not be included in the returned results.

describe will return an array containing information on the instance.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->describe('instanceId');

Terminated Instances

Recently terminated instances might appear in the returned results. This interval is usually less than one hour. If you do not want terminated instances to be returned, pass in a second variable of boolean TRUE to describe and the terminated instances will be ignored.

Example 723. Describing Instances By Image Id

describeByImageId is functionally the same as describe but it will only return the instances that are using the provided imageId.

describeByImageId will return an array containing information on the instances thare were started by the passed in imageId

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->describeByImageId('imageId');

Terminated Instances

Recently terminated instances might appear in the returned results. This interval is usually less than one hour. If you do not want terminated instances to be returned, pass in a second variable of boolean TRUE to describe and the terminated instances will be ignored.

Example 724. Retreiving Console Output

consoleOutput retrieves console output for the specified instance.

Instance console output is buffered and posted shortly after instance boot, reboot, and termination. Amazon EC2 preserves the most recent 64 KB output which will be available for at least one hour after the most recent post.

consoleOutput returns an array containing the instanceId, timestamp from the last output and the output from the console.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->consoleOutput('instanceId');

Example 725. Confirm Product Code on an Instance

confirmProduct returns TRUE if the specified product code is attached to the specified instance. The operation returns FALSE if the product code is not attached to the instance.

The confirmProduct operation can only be executed by the owner of the AMI. This feature is useful when an AMI owner is providing support and wants to verify whether a user's instance is eligible.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->confirmProduct('productCode''instanceId');

Example 726. Turn on CloudWatch Monitoring on an Instance(s)

monitor returns the list of instances and their current state of the CloudWatch Monitoring. If the instance does not currently have Monitoring enabled it will be turned on.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->monitor('instanceId');

Example 727. Turn off CloudWatch Monitoring on an Instance(s)

monitor returns the list of instances and their current state of the CloudWatch Monitoring. If the instance currently has Monitoring enabled it will be turned off.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->unmonitor('instanceId');

Zend Framework