| « PreviousNext » | |
![]() ![]() | Did this page help you? Yes | No | Tell us about it... |
To get started with the AWS SDK for Java, you need to set up the following:
AWS Account and Credentials
Java Development Environment
AWS SDK for Java
To access AWS, you will need to sign up for an AWS account.
To sign up for an AWS account
Go to http://aws.amazon.com, and then click Sign Up.
Follow the on-screen instructions.
Part of the sign-up procedure involves receiving a phone call and entering a PIN using the phone keypad.
AWS sends you a confirmation e-mail after the sign-up process is complete. At any time, you can view your current account activity and manage your account by going to http://aws.amazon.com and clicking My Account/Console.
When you sign up, AWS provides you with security credentials that are specific to your account. Two of these credentials, your access key ID and your secret key, are used by the SDK whenever it accesses the services provided by AWS. The security credentials authenticate requests to the service and identify you as the sender of a request. The following examples show these credentials.
Access Key ID Example: AKIAIOSFODNN7EXAMPLE
Secret Access Key Example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
To view your AWS access credentials
Go to the Amazon Web Services website at http://aws.amazon.com.
Click My Account/Console, and then click Security Credentials.
Under Your Account, click Security Credentials.
In the spaces provided, type your user name and password, and then click Sign in using our secure server.
Under Access Credentials, on the Access Keys tab, your access key ID is displayed. To view your secret key, under Secret Access Key, click Show.
Your secret key must remain a secret that is known only by you and AWS. Keep it confidential in order to protect your account. Store it securely in a safe place, and never email it. Do not share it outside your organization, even if an inquiry appears to come from AWS or Amazon.com. No one who legitimately represents Amazon will ever ask you for your secret key.
The AWS SDK for Java requires J2SE Development Kit 6.0 or later. You can download the latest Java software from http://developers.sun.com/downloads/. The SDK also uses the Apache Commons (Code, HTTP Client, and Logging), and Saxon HE third-party packages, which are included in the third-party directory of the SDK.
If you use Eclipse, the AWS Toolkit for Eclipse provides support for the AWS SDK for Java as well as additional management features. For more information on installing the AWS Toolkit for Eclipse, see http://aws.amazon.com/eclipse/. For more information about using the Toolkit for AWS development, go to the Toolkit Getting Started Guide.
Choosing a JVM
For the best performance of your server-based applications with the AWS SDK for Java, we recommend that you use the 64-bit version of the Java Virtual Machine (JVM). This JVM runs only in Server mode, even if you specify the -Client option at run time. Using the 32-bit version of the JVM with the -Server option at run time should provide comparable performance to the 64-bit JVM.
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.
Demonstrates how to make a request to multiple services.
Demonstrates how to use the basic features for Amazon Simple Storage Service (Amazon S3), such as putting and getting an object from Amazon S3.
Demonstrates how to use the basic features for Amazon SimpleDB, including creating and deleting domains, and selecting data from a domain.
Demonstrates how to use the basic features of Amazon Simple Queue Service (Amazon SQS), including adding and getting messages from a queue.
To run a sample from the command line.
Open the AwsCredentials.properties in the sample folder. For example, the Console sample file is located at aws-java-sdk/samples/AwsConsoleApp/AwsCredentials.properties.
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 =
Save the file.
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.
If you use the AWS Toolkit for Eclipse, you can also start a new project in Eclipse based on the AWS SDK for Java or add the SDK to an existing Java project.
Note
After installing the AWS Toolkit for Eclipse, we recommend configuring the toolkit with your security credentials. You can do this anytime by selecting Preferences from the Window menu in Eclipse, and then selecting the AWS Toolkit section.
To run a sample using the AWS Toolkit for Eclipse
Open Eclipse.
Create a new AWS Java project. In Eclipse, on the File menu, point to New, and then click Project. The New Project wizard opens.
Expand the AWS category, then select AWS Java Project.
Click Next. The project settings page is displayed.
Enter a name in the Project Name box. The AWS SDK for Java Samples group displays the samples available in the SDK, as described previously.
Select the samples you want to include in your project by selecting each check box.
Enter your AWS credentials. If you've already configured the AWS Toolkit for Eclipse with your credentials, this is automatically filled in.
Click Finish. The project is created and added to the Project Explorer.
To run the Project
Select the sample .java file you want to run. For example, for the Amazon S3 sample, select S3Sample.java.
Select Run from the Run menu.
To add the SDK to an existing project
Right-click the project in Project Explorer, point to Build Path, and then click Add Libraries.
Select AWS Java SDK, and then click Next and follow the remaining on-screen instructions.
Where Do I Go From Here?
From here, you can check out the tutorials included in this developer guide.
Tutorial: Amazon EC2 Spot Instances
The tutorial explains how to set up a requests for Amazon EC2 Spot Instances, how to determine when they have completed, and how to clean up afterwards.
Tutorial: Advanced Amazon EC2 Spot Request Management
This more advanced tutorial describes topics such as persistent vs. one-time requests, launch groups, and availability groups.
The Additional Resources section has pointers to other resources to assist you in programming AWS.