1 <?xml version="1.0" encoding="UTF-8"?>
3 <sect1 id="zend.service.amazon.ec2.instance">
4 <title>Zend_Service_Amazon_Ec2: Instances</title>
6 <sect2 id="zend.service.amazon.ec2.instance.types">
7 <title>Instance Types</title>
10 Amazon EC2 instances are grouped into two families: standard and
11 High-CPU. Standard instances have memory to <acronym>CPU</acronym> ratios suitable
12 for most general purpose applications; High-CPU instances have
13 proportionally more <acronym>CPU</acronym> resources than memory (RAM) and are well
14 suited for compute-intensive applications. When selecting instance
15 types, you might want to use less powerful instance types for your
16 web server instances and more powerful instance types for your
17 database instances. Additionally, you might want to run <acronym>CPU</acronym> instance
18 types for <acronym>CPU</acronym>-intensive data processing tasks.
22 One of the advantages of EC2 is that you pay by the instance hour,
23 which makes it convenient and inexpensive to test the performance of
24 your application on different instance families and types. One good
25 way to determine the most appropriate instance family and instance
26 type is to launch test instances and benchmark your application.
30 <title>Instance Types</title>
33 The instance types are defined as constants in the code. Column eight
34 in the table is the defined constant name
38 <table id="zend.service.amazon.ec2.instance.types-table">
39 <title>Available Instance Types</title>
45 <entry><acronym>CPU</acronym></entry>
47 <entry>Storage</entry>
48 <entry>Platform</entry>
51 <entry>Constant Name</entry>
57 <entry><code>Small</code></entry>
61 1 <constant>EC2</constant> Compute Unit (1 virtual core with 1
62 <constant>EC2</constant> Compute Unit)
66 <entry><para>1.7 GB</para></entry>
69 <para>160 GB instance storage (150 GB plus 10 GB root partition)</para>
72 <entry><para>32-bit</para></entry>
73 <entry><para>Moderate</para></entry>
74 <entry><para>m1.small</para></entry>
75 <entry><constant>Zend_Service_Amazon_Ec2_Instance::SMALL</constant></entry>
79 <entry><code>Large</code></entry>
83 4 <constant>EC2</constant> Compute Units (2 virtual cores with 2
84 <constant>EC2</constant> Compute Units each)
88 <entry><para>7.5 GB</para></entry>
92 850 GB instance storage (2 x 420 GB plus 10 GB root partition)
96 <entry><para>64-bit</para></entry>
97 <entry><para>High</para></entry>
98 <entry><para>m1.large</para></entry>
99 <entry><constant>Zend_Service_Amazon_Ec2_Instance::LARGE</constant></entry>
103 <entry><code>Extra Large</code></entry>
106 8 <constant>EC2</constant> Compute Units (4 virtual cores with 2
107 <constant>EC2</constant> Compute Units each)
111 <entry><para>15 GB</para></entry>
115 1,690 GB instance storage (4 x 420 GB plus 10 GB root partition)
119 <entry><para>64-bit</para></entry>
120 <entry><para>High</para></entry>
121 <entry><para>m1.xlarge</para></entry>
122 <entry><constant>Zend_Service_Amazon_Ec2_Instance::XLARGE</constant></entry>
126 <entry><code>High-CPU Medium</code></entry>
130 5 <constant>EC2</constant> Compute Units (2 virtual cores with 2.5
131 <constant>EC2</constant> Compute Units each)
135 <entry><para>1.7 GB</para></entry>
138 <para>350 GB instance storage (340 GB plus 10 GB root partition)</para>
141 <entry><para>32-bit</para></entry>
142 <entry><para>Moderate</para></entry>
143 <entry><para>c1.medium</para></entry>
146 <constant>Zend_Service_Amazon_Ec2_Instance::HCPU_MEDIUM</constant>
151 <entry><code>High-CPU Extra Large</code></entry>
155 20 <constant>EC2</constant> Compute Units (8 virtual cores with 2.5
156 <constant>EC2</constant> Compute Units each)
160 <entry><para>7 GB</para></entry>
164 1,690 GB instance storage (4 x 420 GB plus 10 GB root partition)
168 <entry><para>64-bit</para></entry>
169 <entry><para>High</para></entry>
170 <entry><para>c1.xlarge</para></entry>
173 <constant>Zend_Service_Amazon_Ec2_Instance::HCPU_XLARGE</constant>
181 <sect2 id="zend.service.amazon.ec2.instance.operations">
182 <title>Running Amazon EC2 Instances</title>
185 This section describes the operation methods for maintaining Amazon EC2 Instances.
188 <example id="zend.service.amazon.ec2.instance.operations.run">
189 <title>Starting New Ec2 Instances</title>
192 <code>run</code> will launch a specified number of EC2 Instances.
193 <code>run</code> takes an array of parameters to start, below is a table
194 containing the valid values.
198 <table id="zend.service.amazon.ec2.instance.operations.run-table">
199 <title>Valid Run Options</title>
205 <entry>Description</entry>
206 <entry>Required</entry>
212 <entry><code>imageId</code></entry>
216 ID of the <acronym>AMI</acronym> with which to launch
221 <entry><para>Yes</para></entry>
225 <entry><code>minCount</code></entry>
228 <para>Minimum number of instances to launch. Default: 1</para>
231 <entry><para>No</para></entry>
235 <entry><code>maxCount</code></entry>
238 <para>Maximum number of instances to launch. Default: 1</para>
241 <entry><para>No</para></entry>
245 <entry><code>keyName</code></entry>
249 Name of the key pair with which to launch instances.
250 If you do not provide a key, all instances will
255 <entry><para>No</para></entry>
259 <entry><code>securityGroup</code></entry>
263 Names of the security groups with which to associate
268 <entry><para>No</para></entry>
272 <entry><code>userData</code></entry>
276 The user data available to the launched instances.
277 This should not be Base64 encoded.
281 <entry><para>No</para></entry>
285 <entry><code>instanceType</code></entry>
289 Specifies the instance type. Default: m1.small
293 <entry><para>No</para></entry>
297 <entry><code>placement</code></entry>
301 Specifies the availability zone in which to
302 launch the instance(s). By default, Amazon
303 <constant>EC2</constant> selects an availability zone for
308 <entry><para>No</para></entry>
312 <entry><code>kernelId</code></entry>
316 The ID of the kernel with which to launch
321 <entry><para>No</para></entry>
325 <entry><code>ramdiskId</code></entry>
329 The ID of the <acronym>RAM</acronym> disk with which to
334 <entry><para>No</para></entry>
338 <entry><code>blockDeviceVirtualName</code></entry>
342 Specifies the virtual name to map to the
343 corresponding device name. For example:
348 <entry><para>No</para></entry>
352 <entry><code>blockDeviceName</code></entry>
356 Specifies the device to which you are
357 mapping a virtual name. For example: sdb
361 <entry><para>No</para></entry>
364 <entry><code>monitor</code></entry>
368 Turn on <acronym>AWS</acronym> CloudWatch Instance
373 <entry><para>No</para></entry>
381 <code>run</code> will return information about each instance
385 <programlisting language="php"><![CDATA[
386 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
388 $return = $ec2_instance->run(array('imageId' => 'ami-509320',
389 'keyName' => 'myKey',
390 'securityGroup' => array('web',
395 <example id="zend.service.amazon.ec2.instance.operations.reboot">
396 <title>Rebooting an Ec2 Instances</title>
399 <code>reboot</code> will reboot one or more instances.
403 This operation is asynchronous; it only queues a request to
404 reboot the specified instance(s). The operation will succeed
405 if the instances are valid and belong to the user. Requests
406 to reboot terminated instances are ignored.
410 <code>reboot</code> returns boolean <constant>TRUE</constant> or
411 <constant>FALSE</constant>
414 <programlisting language="php"><![CDATA[
415 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
417 $return = $ec2_instance->reboot('instanceId');
421 <example id="zend.service.amazon.ec2.instance.operations.terminate">
422 <title>Terminating an Ec2 Instances</title>
425 <code>terminate</code> shuts down one or more instances. This
426 operation is idempotent; if you terminate an instance more
427 than once, each call will succeed.
431 <code>terminate</code> returns boolean <constant>TRUE</constant> or
432 <constant>FALSE</constant>
435 <programlisting language="php"><![CDATA[
436 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
438 $return = $ec2_instance->terminate('instanceId');
443 <title>Terminated Instances</title>
444 <para>Terminated instances will remain visible after termination
445 (approximately one hour).</para>
449 <sect2 id="zend.service.amazon.ec2.instance.utility">
450 <title>Amazon Instance Utilities</title>
453 In this section you will find out how to retreive information, the console
454 output and see if an instance contains a product code.
457 <example id="zend.service.amazon.ec2.instance.utility.describe">
458 <title>Describing Instances</title>
461 <code>describe</code> returns information about instances that you own.
465 If you specify one or more instance IDs, Amazon EC2 returns information
466 for those instances. If you do not specify instance IDs, Amazon EC2
467 returns information for all relevant instances. If you specify an invalid
468 instance ID, a fault is returned. If you specify an instance that you do
469 not own, it will not be included in the returned results.
473 <code>describe</code> will return an array containing information on the
477 <programlisting language="php"><![CDATA[
478 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
480 $return = $ec2_instance->describe('instanceId');
485 <title>Terminated Instances</title>
488 Recently terminated instances might appear in the returned results. This interval is
489 usually less than one hour. If you do not want terminated instances to be returned,
490 pass in a second variable of boolean <constant>TRUE</constant> to
491 <code>describe</code> and the terminated instances will be ignored.
495 <example id="zend.service.amazon.ec2.instance.utility.describebyimageid">
496 <title>Describing Instances By Image Id</title>
499 <code>describeByImageId</code> is functionally the same as <code>describe</code>
500 but it will only return the instances that are using the provided imageId.
504 <code>describeByImageId</code> will return an array containing information on the
505 instances thare were started by the passed in imageId
508 <programlisting language="php"><![CDATA[
509 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
511 $return = $ec2_instance->describeByImageId('imageId');
516 <title>Terminated Instances</title>
519 Recently terminated instances might appear in the returned results. This
520 interval is usually less than one hour. If you do not want terminated
521 instances to be returned, pass in a second variable of boolean
522 <constant>TRUE</constant> to <code>describe</code> and the terminated instances
527 <example id="zend.service.amazon.ec2.instance.utility.consoleOutput">
528 <title>Retreiving Console Output</title>
531 <code>consoleOutput</code> retrieves console output for the specified
536 Instance console output is buffered and posted shortly after instance
537 boot, reboot, and termination. Amazon EC2 preserves the most recent
538 64 KB output which will be available for at least one hour after the
543 <code>consoleOutput</code> returns an array containing the
544 <code>instanceId</code>, <code>timestamp</code> from the last output
545 and the <code>output</code> from the console.
548 <programlisting language="php"><![CDATA[
549 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
551 $return = $ec2_instance->consoleOutput('instanceId');
555 <example id="zend.service.amazon.ec2.instance.utility.confirmproduct">
556 <title>Confirm Product Code on an Instance</title>
559 <code>confirmProduct</code> returns <constant>TRUE</constant> if the specified
560 product code is attached to the specified instance. The operation returns
561 <constant>FALSE</constant> if the product code is not attached to the instance.
565 The <code>confirmProduct</code> operation can only be executed by the owner of the
566 <acronym>AMI</acronym>. This feature is useful when an <acronym>AMI</acronym> owner
567 is providing support and wants to verify whether a user's instance is eligible.
570 <programlisting language="php"><![CDATA[
571 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
573 $return = $ec2_instance->confirmProduct('productCode', 'instanceId');
577 <example id="zend.service.amazon.ec2.instance.utility.monitor">
578 <title>Turn on CloudWatch Monitoring on an Instance(s)</title>
581 <code>monitor</code> returns the list of instances and their
582 current state of the CloudWatch Monitoring. If the instance
583 does not currently have Monitoring enabled it will be turned on.
586 <programlisting language="php"><![CDATA[
587 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
589 $return = $ec2_instance->monitor('instanceId');
593 <example id="zend.service.amazon.ec2.instance.utility.unmonitor">
594 <title>Turn off CloudWatch Monitoring on an Instance(s)</title>
597 <code>monitor</code> returns the list of instances and their
598 current state of the CloudWatch Monitoring. If the instance
599 currently has Monitoring enabled it will be turned off.
602 <programlisting language="php"><![CDATA[
603 $ec2_instance = new Zend_Service_Amazon_Ec2_Instance('aws_key',
605 $return = $ec2_instance->unmonitor('instanceId');