Resources



Sample Code and Libraries

Java Library for Amazon EC2

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

Java Library for Amazon EC2

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

What's New?

  • 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
  • 2009-02-11:
    • Update for signature version 2
  • 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-09-23:
  • 2008-08-26:
    • Fix issue with wrong definition of IpPermission element in SecurityGroup. It is now correctly defined as list.
  • 2008-08-20: Initial release, support for Amazon Elastic Block Store

Prerequisites

Reference Documentation

Package Content

Path Overview
dist Binary distribution of library
src Source distribution of library.
third-party Binary distribution of library dependencies.
build.xml Ant build file to build the 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 download file into a working directory.
  2. Add all sources under "src" directory to your compilation path.
  3. Add all jars files under "third-party/*" directory to your classpath
  4. Edit desired sample. For example: DescribeImagesSample.java


    • Set AWS Access Key ID and AWS Secret Access Key
    • String accessKeyId = "Your Access Key ID";
      String secretAccessKey = "Your Secret Access Key";
                      


    • Set request parameters. For example, find following pre-generated snippet:
    • DescribeImagesRequest request = new DescribeImagesRequest();
      // @TODO: set request parameters here
      // invokeDescribeImages(service, request);
                      


    • And uncomment third line and add:
    • DescribeImagesRequest request = new DescribeImagesRequest()
                                          .withImageId("ami-be3adfd7");
      invokeDescribeImages(service, request);
                      

  5. Compile and run DescribeImagesSample. You should see the output similar to the following:


  6.     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
                    ...
    
                

    Note, to see additional debugging output, adjust level of debugging in log4j.properties available in the root of the source tree.

  7. Experiment with samples. When ready, add library binary distribution to your application classpath, 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:

    AmazonEC2Config ec2Config = new AmazonEC2Config()
        .withServiceURL("https://eu-west-1.ec2.amazonaws.com"));        
    AmazonEC2 service = new AmazonEC2Client(accessKeyId, secretAccessKey, ec2Config); 

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

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.

nomoneydown
Posts: 11
Registered: 9/5/09
Static code/name values?
Posted: Sep 5, 2009 4:46 PM PDT   in response to: Elena@AWS
 
  Click to reply to this thread Reply

I have been searching in vain for what all the defined codes/names are for Amazon response data types, for example, all the values getCode() and getName() can return in the InstanceState class.  Has Amazon frozen these yet, and, if so, where can I find a complete list of them?


dafaleiting
Posts: 57
Registered: 8/10/09
Re: Service Error. Response Status: 200
Posted: Oct 5, 2009 2:03 PM PDT   in response to: Elena@AWS
 
  Click to reply to this thread Reply

Are there plans to support the Load Balancing API?


D. Kavanagh
RealName(TM)

Posts: 2,716
Registered: 5/25/06
Re: Service Error. Response Status: 200
Posted: Oct 7, 2009 6:03 AM PDT   in response to: dafaleiting
 
  Click to reply to this thread Reply

typica ( http://code.google.com/p/typica/) supports ELB and AS as well as CloudWatch

karimhamdan
Posts: 1
Registered: 1/11/09
Re: Java Library for Amazon EC2 in M2 repo?
Posted: Nov 1, 2009 7:28 PM PST   in response to: Jayachandran Ar...
 
  Click to reply to this thread Reply

Hi Jayachandran,

You can access the private IP address of an instance through the method getPrivateDns() in an object of type Instance .


Peco K
Posts: 1
Registered: 1/12/10
Latest javadoc for ec2-2009-11-30.jar
Posted: Jan 12, 2010 8:28 AM PST   in response to: marthursson
 
  Click to reply to this thread Reply

Hello,
I am trying to find the latest javadoc for the last revision of the Java SDK. The javadoc link on the site points to " http://s3.amazonaws.com/awscode/amazon-ec2/2009-08-15 /java/library/doc/index.html".

I tried http://s3.amazonaws.com/awscode/amazon-ec2/latest /java/library/doc/index.html and http://s3.amazonaws.com/awscode/amazon-ec2/2009-11-30 /java/library/doc/index.html but neither are available.

thanks!



Reviews
Create Review Write a Review

Find for svn access, Nov 26, 2009 6:30 PM
Reviewer: leniks
Hi, I'm living at bleeding edge, is there any SVN/CVS access to this library, or maven2 repository? So I don't have to check new version and updates days and days.

SDK is a great resource for Java developers, Jan 12, 2010 8:18 AM
Reviewer: Peco K
So far it has been a great experience working with the SDK. Getting it installed even without a maven public repo was a breeze with not external dependencies to keep track of and configure. It is easy to understand and the samples provide a quick path to get started. The fact that the AWS dev staff keeps it rev-ed closed to the API release dates is really encouraging! keep up the great work! Cheers
Welcome, Guest Help
Login Login