AWS SDK for Java Documentation Examples
These are examples for the AWS SDK for Java public documentation.
To build and run these examples, you'll need:
- Apache Maven (>3.0)
- AWS SDK for Java (downloaded and extracted somewhere on your machine)
- AWS credentials, either configured in a local AWS credentials file or by setting the
- You should also set the AWS region within which the operations will be performed. If a region is
not set, the default region used will be
For information about how to set AWS credentials and the region for use with the AWS SDK for Java, see Set up AWS Credentials and Region for Development in the AWS Java Developer Guide.
Building the examples
The examples are divided into directories by AWS service (
dynamodb, and so on). Within
each, you'll find a
pom.xml file used for building the examples with Maven, and a
that wraps the Maven commands for those of you who also have
To build, open a command-line (terminal) window and change to the directory containing the examples you want to build/run. Then type:
or, if you have
make, you can simply type:
to begin the build process. Maven will download any dependencies (such as components of the AWS SDK for Java) that it needs for building.
Once the examples have been built, you can run them to see them in action.
If you are running on a platform with
make, you can also use the provided Makefiles to
build the examples, by running
make in any directory with a
Makefile present. You must
still have Maven installed, however (the Makefile wraps Maven commands).
Running the examples
The examples perform AWS operations for the account and region for which you've specified credentials, and you may incur AWS service charges by running them. Please visit the AWS Pricing page for details about the charges you can expect for a given service and operation.
Some of these examples perform destructive operations on AWS resources, such as deleting an Amazon S3 bucket or an Amazon DynamoDB table. Be very careful when running an operation that may delete or modify AWS resources in your account. It's best to create separate test-only resources when experimenting with these examples.
To run these examples, you'll need the AWS SDK for Java libraries in your
/path/to/aws-java-sdk is the path to where you extracted the AWS Java SDK download (it
Once you set the
CLASSPATH, you can run a particular example like this:
java aws.example.s3.ListBuckets -cp target/s3examples-1.0.jar:$CLASSPATH
For systems with bash support
As an alternative to setting the
CLASSPATH and specifying the full namespace of the class to
run, we've included a
run_example.sh, that you can use on Linux, Unix or OS X
(or on Windows by using Cygwin, MingW, or
Bash on Ubuntu on Windows).
To use the script, set the path to the Java SDK directory in the
variable. For example:
Once you've set the variable, you can execute
run_example.sh as shown:
This will run the ListBuckets example (assuming that you've built the examples first!).