Documentation

Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI) - Zend_Service

Zend_Service_Amazon_Ec2: Amazon Machine Images (AMI)

Amazon Machine Images (AMIs) are preconfigured with an ever-growing list of operating systems.

AMI Information Utilities

Example #1 Register an AMI with EC2

register Each AMI is associated with an unique ID which is provided by the Amazon EC2 service through the RegisterImage operation. During registration, Amazon EC2 retrieves the specified image manifest from Amazon S3 and verifies that the image is owned by the user registering the image.

register returns the imageId for the registered Image.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. $ip = $ec2_img->register('imageLocation');

Example #2 Deregister an AMI with EC2

deregister, Deregisters an AMI. Once deregistered, instances of the AMI can no longer be launched.

deregister returns boolean TRUE or FALSE.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. $ip = $ec2_img->deregister('imageId');

Example #3 Describe an AMI

describe Returns information about AMIs, AKIs, and ARIs available to the user. Information returned includes image type, product codes, architecture, and kernel and RAM disk IDs. Images available to the user include public images available for any user to launch, private images owned by the user making the request, and private images owned by other users for which the user has explicit launch permissions.

Launch permissions fall into three categories
Name Description
public

The owner of the AMI granted launch permissions for the AMI to the all group. All users have launch permissions for these AMIs.

explicit

The owner of the AMI granted launch permissions to a specific user.

implicit

A user has implicit launch permissions for all AMIs he or she owns.

The list of AMIs returned can be modified by specifying AMI IDs, AMI owners, or users with launch permissions. If no options are specified, Amazon EC2 returns all AMIs for which the user has launch permissions.

If you specify one or more AMI IDs, only AMIs that have the specified IDs are returned. If you specify an invalid AMI ID, a fault is returned. If you specify an AMI ID for which you do not have access, it will not be included in the returned results.

If you specify one or more AMI owners, only AMIs from the specified owners and for which you have access are returned. The results can include the account IDs of the specified owners, amazon for AMIs owned by Amazon or self for AMIs that you own.

If you specify a list of executable users, only users that have launch permissions for the AMIs are returned. You can specify account IDs (if you own the AMI(s)), self for AMIs for which you own or have explicit permissions, or all for public AMIs.

describe returns an array for all the images that match the critera that was passed in. The array contains the imageId, imageLocation, imageState, imageOwnerId, isPublic, architecture, imageType, kernelId, ramdiskId and platform.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. $ip = $ec2_img->describe();

AMI Attribute Utilities

Example #4 Modify Image Attributes

Modifies an attribute of an AMI

Valid Attributes
Name Description
launchPermission

Controls who has permission to launch the AMI. Launch permissions can be granted to specific users by adding userIds.

To make the AMI public, add the all group.

productCodes

Associates a product code with AMIs. This allows developers to charge users for using AMIs. The user must be signed up for the product before they can launch the AMI. This is a write once attribute; after it is set, it cannot be changed or removed.

modifyAttribute returns boolean TRUE or FALSE.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. // modify the launchPermission of an AMI
  3. $return = $ec2_img->modifyAttribute('imageId',
  4.                                     'launchPermission',
  5.                                     'add',
  6.                                     'userId',
  7.                                     'userGroup');
  8.  
  9. // set the product code of the AMI.
  10. $return = $ec2_img->modifyAttribute('imageId',
  11.                                     'productCodes',
  12.                                     'add',
  13.                                     null,
  14.                                     null,
  15.                                     'productCode');

Example #5 Reset an AMI Attribute

resetAttribute will reset the attribute of an AMI to its default value. The productCodes attribute cannot be reset.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. $return = $ec2_img->resetAttribute('imageId', 'launchPermission');

Example #6 Describe AMI Attribute

describeAttribute returns information about an attribute of an AMI. Only one attribute can be specified per call. Currently only launchPermission and productCodes are supported.

describeAttribute returns an array with the value of the attribute that was requested.

  1. $ec2_img = new Zend_Service_Amazon_Ec2_Image('aws_key','aws_secret_key');
  2. $return = $ec2_img->describeAttribute('imageId', 'launchPermission');

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts