Using the AWS SDK for Java

By: Emiley J Viewed: 153345 times  Printer Friendly Format    


Download the AWS SDK for Java from the SDK web page at http://aws.amazon.com/sdkforjava. After downloading the SDK, extract the contents into a folder.

The SDK /samples folder includes a number of code samples:

  • Console sample – Demonstrates how to make a request to multiple services.
  • Amazon S3 sample – Demonstrates how to use the basic features for Amazon S3, such as putting and getting an object from Amazon S3.
  • Amazon SimpleDB sample – Demonstrates how to use the basic features for Amazon SimpleDB, including creating and deleting domains, and selecting data from a domain.
  • Amazon SQS sample – Demonstrates how to use the basic features of Amazon SQS, including adding and getting messages from a queue.

To run a sample

  1. Open the AwsCredentials.properties in the sample folder. For example, the Console sample file is located at aws-java-sdk/samples/AwsConsoleApp/AwsCredentials.properties.
  2. Locate the following section and fill in your Access Key ID and Secret Access Key:

    # Fill in your AWS Access Key ID and Secret Access Key
    # http://aws.amazon.com/security-credentials
    accessKey =
    secretKey =

  3. Save the file.
  4. Run the .java file for your sample, located in the same directory as the properties file. For example, run the aws-java-sdk/samples/AwsConsoleApp/AwsConsoleApp.java file for the Console sample. The sample prints information to the standard output, for example:

    ===========================================
    
      Welcome to the AWS Java SDK!
    
    ===========================================

     

    You have access to 4 Availability Zones.
    You have 0 Amazon EC2 instance(s) running.
    You have 13 Amazon SimpleDB domain(s)containing a total of 62 items.
    You have 23 Amazon S3 bucket(s), containing 44 objects with a total size of 154767691 bytes.

NOTE: Each sample also includes an Ant build.xml file to run the sample. For more information on Ant, see http://ant.apache.org.



Most Viewed Articles (in Java )

Latest Articles (in Java)

Comment on this tutorial