Amazon DynamoDB
Developer Guide (API Version 2012-08-10)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

Running Java Examples for DynamoDB

General Process of Creating Java Code Examples (Using Eclipse)

1

Download and install the AWS Toolkit for Eclipse. This toolkit includes the AWS SDK for Java, along with preconfigured templates for building applications.

2

From the Eclipse menu, click File, New, Other...

In the Select a wizard box, click File, AWS Java Project, Click Next.

In the Project name field, type a name for your project. Click Finish to create the project. Note that the project is pre-configured, and includes the AWS SDK for Java .jar files.

3

You will now need to create a default credential profiles file. This file enhances security by storing your credentials separately from your project directories, so that they cannot be unintentionally committed to a public repository. For more information, see Using the Default Credential Provider Chain in the AWS SDK for Java Developer Guide.

The credential properties file should be created in ~/.aws/credentials, where the tilde character represents your home directory. In this file, you can store multiple sets of credentials from any number of accounts. Each set is referred to as a profile. The following is an example of a credential properties file witha a profile named default:

[default]
aws_access_key_id = <Your Access Key ID>
aws_secret_access_key = <Your Secret Key>

The code examples in this document use the default client constructors that read your AWS credentials stored in the credential properties file.

4

Copy the code from the section that you are reading to your project.

5

Run the code.


Setting the Region

You can set the DynamoDB region explicitly, as shown in the following Java code snippet.

client = new AmazonDynamoDBClient(credentials);
client.setRegion(Region.getRegion(Regions.US_WEST_2)); 

For a current list of supported regions and endpoints, see Regions and Endpoints.