Submit a Resource

PHP Library for Amazon EC2

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

PHP Library for Amazon EC2

Submitted By: Jason@AWS  
AWS Products Used: Amazon EC2
Language(s): PHP
License: Apache License 2.0

What's New?

  • 2010-07-21:
    • Support for Amazon EC2 API Version 2010-06-15.
  • 2009-12-13:
    • Support for Amazon EC2 API Version 2009-11-30.
  • 2009-12-02:
    • Support for Amazon EC2 API Version 2009-10-31.
  • 2009-09-29:
    • Fix typo and response transformation on VpcAttachment
  • 2009-09-28:
  • 2009-09-23:
    • Support for Shared Snapshots API
  • 2009-09-10:
    • Fix for missing VPC fields on RunningInstance
  • 2009-08-25:
    • Support for VPC API
  • 2009-05-17:
    • Support for monitoring API
  • 2009-04-09:
    • Support for reserved instances API
  • 2008-12-24:
    • Fix notice output (no side effects, just noise)
  • 2008-12-23:
    • Url encoding fix (some calls with signature version 2 were affected)
  • 2008-12-17:
    • Support for regions, signature version 2, https endpoint
  • 2008-10-21:
    • Support for Windows Bundling, new API version - 2008-08-08
  • 2008-08-26:
    • Fix issue with wrong definition of IpPermission element in SecurityGroup. It is now correctly defined as list.
    • Update internal signing to use built-in hash_hmac
  • 2008-08-20: Initial release, support for Amazon Elastic Block Store

Prerequisites

Package Content

Directory Overview
src Source distribution of library.

Quick Start

Library comes with code samples for each available service API. To get started with the library, follow these steps:
  1. Extract the downlaod file into a working directory.
  2. Go to src/Amazon/EC2/Samples subdirectopry
  3. Edit .config.inc.php:


    • Set AWS Access Key ID and AWS Secret Access Key
    •     define('AWS_ACCESS_KEY_ID', '<Your Access Key ID>');
          define('AWS_SECRET_ACCESS_KEY', '<Your Secret Access Key>');
                      


    • Open DescribeImagesSample.php sample, and find part:
    •  // @TODO: set request. Action can be passed as Amazon_EC2_Model_DescribeImagesRequest
       // object or array of parameters
       // invokeDescribeImages($service, $request);
                      


    • And uncomment:
    •  invokeDescribeImages($service, array('ImageId' => 'ami-be3adfd7'));
                      

  4. Run DescribeImages sample:
  5.    php src/Amazon/EC2/Samples/DescribeImagesSample.php
                
  6. You should see the output similar to the following:


  7.     DescribeImagesResponse
            DescribeImagesResult
                Image
                    ImageId
                        ami-be3adfd7
                    ImageLocation
                        ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml
                    ImageState
                        available
                    KernelId
                        aki-4438dd2d
                    RamdiskId
                        ari-4538dd2c
                    ...
                

  8. Experiment with samples. When ready, install library in your php include path and use it

Making Requests to a Different Region

To make a service call to a different region, instantiate the client with a configuration object, and pass the region-specific endpoint. For example:

    $ec2Config = array ('ServiceURL' => 'https://eu-west-1.ec2.amazonaws.com');
    $ec2 = new Amazon_EC2_Client($accessKeyId, $secretAccessKey, $ec2Config);

Please see the Amazon EC2 Developer Guide for a complete list of region endpoints.

Notes

You can use alternative array-based interface with the library. For example, instead of:

    $request = new Amazon_EC2_Model_DescribeImages();
    $request->setImageId('ami-be3adfd7');
    $response = $service->describeImages($request);
        
You can write:
    $response = $service->describeImages(array('ImageId' => 'ami-be3adfd7'));
        

Happy coding!

Comments, Questions or Feedback

If you have any comments, questions or feedback on the library, please start discussion here.

Discussion

The 5 most recent discussion messages. View full discussion.

samuraihash
Posts: 4
Registered: 8/27/08
PHP Library for Amazon EC2
Posted: Sep 21, 2008 5:01 AM PDT
 
  Click to reply to this thread Reply

How do i determine the instance ID of the current instance, when you have multiple instances running? Supplying $request as NULL returns a list of all instances right? So how do you determine the local ID in php?

thanks in advance

samuraihash
Posts: 4
Registered: 8/27/08
Re: PHP Library for Amazon EC2
Posted: Sep 25, 2008 2:15 PM PDT   in response to: samuraihash
 
  Click to reply to this thread Reply

Ok i solved this one by exporting the instance id to an environment variable at startup:

export INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`

then calling getenv in php:

echo getenv('INSTANCE_ID');

this works in CLI also.



drindt
Posts: 13
Registered: 10/31/08
Re: PHP Library for Amazon EC2
Posted: Mar 29, 2009 10:59 PM PDT   in response to: samuraihash
 
  Click to reply to this thread Reply

i have the volume vol-30896c59 in eu-west-1a and my code isnt able to frequently snapshot it because the api throws the exception 'The volume 'vol-30896c59' does not exist.'

what iam doing wrong?


Todd Chaffee
Posts: 2
Registered: 6/22/09
Re: PHP Library for Amazon EC2
Posted: Jun 29, 2009 1:04 PM PDT   in response to: samuraihash
 
  Click to reply to this thread Reply

The link in the article to the PHP documentation doesn't work.  It shows an XML file that says "Access Denied".



Reviews
Create Review Write a Review

Missing Documentation, Jul 6, 2009 3:23 PM
Reviewer: joehung
The PHPDocs are still unaccessible. Please resolve this!
Welcome, Guest Help
Login Login