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

Running Amazon EC2 Instances

This section describes the operation methods for maintaining Amazon EC2 Instances.

Example 719. Starting New Ec2 Instances

run will launch a specified number of EC2 Instances. run takes an array of parameters to start, below is a table containing the valid values.

Table 148. Valid Run Options

Name Description Required
imageId

ID of the AMI with which to launch instances.

Yes

minCount

Minimum number of instances to launch. Default: 1

No

maxCount

Maximum number of instances to launch. Default: 1

No

keyName

Name of the key pair with which to launch instances. If you do not provide a key, all instances will be inaccessible.

No

securityGroup

Names of the security groups with which to associate the instances.

No

userData

The user data available to the launched instances. This should not be Base64 encoded.

No

instanceType

Specifies the instance type. Default: m1.small

No

placement

Specifies the availability zone in which to launch the instance(s). By default, Amazon EC2 selects an availability zone for you.

No

kernelId

The ID of the kernel with which to launch the instance.

No

ramdiskId

The ID of the RAM disk with which to launch the instance.

No

blockDeviceVirtualName

Specifies the virtual name to map to the corresponding device name. For example: instancestore0

No

blockDeviceName

Specifies the device to which you are mapping a virtual name. For example: sdb

No

monitor

Turn on AWS CloudWatch Instance Monitoring

No


run will return information about each instance that is starting up.

<?php
$ec2_instance 
= new Zend_Service_Amazon_Ec2_Instance('aws_key',
                                                     
'aws_secret_key');
$return $ec2_instance->run(array('imageId' => 'ami-509320',
                                   
'keyName' => 'myKey',
                                   
'securityGroup' => array('web',
                                                            
'default')));

Example 720. Rebooting an Ec2 Instances

reboot will reboot one or more instances.

This operation is asynchronous; it only queues a request to reboot the specified instance(s). The operation will succeed if the instances are valid and belong to the user. Requests to reboot terminated instances are ignored.

reboot returns boolean TRUE or FALSE

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

Example 721. Terminating an Ec2 Instances

terminate shuts down one or more instances. This operation is idempotent; if you terminate an instance more than once, each call will succeed.

terminate returns boolean TRUE or FALSE

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

Terminated Instances

Terminated instances will remain visible after termination (approximately one hour).

Zend Framework