In this post, I will guide you how to setup a Java Maven project to use Amazon Web Services (AWS) Software Development Kit (SDK) for Amazon S3 (Simple Storage Service) development.

To follow this guide, you must have an AWS account and an IAM admin user. Here are the steps for installing AWS Java SDK for your project:

  • Generate AWS programmatic credentials, i.e. Access Key ID and Secret Access Key
  • Store AWS configuration via system environment variable, Java system properties or config file
  • Declare dependency for AWS Java SDK and Amazon S3

Let’s go through each step in details.

 

1. Generate AWS Access Key ID and Secret Access Key

Follow this guide to create AWS access keys. Then copy the values of Access key ID and Secret access key, which will be used in the next step.


2. Store AWS Configuration

There are 3 ways to store AWS configuration (Region, Access key ID and Secret Access Key) on development computer: in user/system properties, in config file or in Java system properties. And my preferred way is using system properties, so I will show you how.

On Windows, open the Environment Variables dialog, and add 3 new system variables as shown below:

store aws configs in system variables

Note that the name of 3 variables are AWS_REGION, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY. You can get the AWS region from S3 service in AWS management console.


3. Declare Dependency for AWS Java SDK and Amazon S3

Now, in the pom.xml file of your Java Maven project, put the following XML code:

<project ...>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>software.amazon.awssdk</groupId>
				<artifactId>bom</artifactId>
				<version>2.15.0</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

	<dependencies>
		<dependency>
			<groupId>software.amazon.awssdk</groupId>
			<artifactId>s3</artifactId>
		</dependency>
	</dependencies>
	
</project>

The dependencyManagement section imports a Bill of Materials (bom) for AWS SDK for Java. Then the dependency section specifies the dependency needed for Amazon S3 development only.

That’s done. Now you’re all set for writing code that uses Amazon S3 API from AWS Java SDK.

To see the steps in action, I recommend you to watch this video:

 

Related Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.