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:
Let’s go through each step in details.
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.
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:
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.
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: