An AmazonWebServicesS3 bucket is an inexpensive option to store your Maven or other binary artifacts. It’s an alternative to feature-rich Maven repository managers like Nexus and Artifactory when you don’t have the resources to install and maintain a server with the required software or the budget to subscribe to a hosted plan.
One choice I wouldn’t recommend is to store the binary artifacts in the SCM.
This “how to” post covers configuring Maven and setting up an AWSS3 bucket to store Java artifacts.
Click on Services -> IAM -> Policies -> Create policy and paste this policy in the JSON tab:
Creating a AWS IAM Policy - JSON
Click on Review policy and Create policy to complete it. This tutorial uses Name=maven-repo-tutorial-policy.
Creating an AWS IAM Policy - Name and Service
2.3. CREATE IAM USER
Click on Services -> IAM -> Users -> Add user. This tutorial uses User name=maven-repo-tutorial-user and Access type=Programmatic access, because this guide uses the Access Key ID and the Secret Access Key as the credentials.
Click on Review and Create user buttons and store the Access key ID and Secret access key pair associated the created user in a safe medium.
Warning: Don’t expose any of the AWSIAM user’s Access key ID and Secret access key.
Now that the AmazonS3 bucket with corresponding permissions is ready, lets change a Java application.
3. CONFIGURING MAVEN AND APPLICATION TO BE DEPLOYED TO AN S3 BUCKET
Include these updates on the Maven and application side:
This change could be included in your existing ~/.m2/settings.xml or in a new file as done in this tutorial.
You could paste Access key ID and Secret access key into username and password elements directly, but please make sure this file is protected and/or the password is encrypted.
Or you could pass these values via VM arguments -Diam-user-access-key-id=XXXX, -Diam-user-secret-key=XXXX.
aws-maven is a MavenWagon for AWSS3, used to publish artifacts to an S3 bucket.
And that’s it configuring a Maven application or module, let’s now deploy an artifact.
4. DEPLOYING AN ARTIFACT TO AN S3 BUCKET
4.1. DEPLOYING A SNAPSHOT
Deploying a Maven snapshot artifact to an AWS S3 Bucket
4.2. DEPLOYING A RELEASE
This command updates the version of the artifact.
Deploying a Maven release artifact to an AWS S3 Bucket
It could be seen both, a snapshot and a release artifacts were successfully deployed to an S3 bucket.
Similarly to deploying an artifact, Maven applications can be configured to fetch dependencies from an S3 bucket.
This solution would be valid for a solo developer or a small team. Although a better choice than checking in the resulting artifacts into the SCM, it has some limitations. You won’t be able to Search for an artifact, which is convenient when you need to find out the artifactId, groupId and version of a dependency. Another limitation is maintenance. As the snapshot folder grows overtime, you would have to manually remove older versions.
A solution to these problems could be automated when using a feature-rich Maven repository manager like Nexus or Artifactory but as mentioned in the Introduction, it would also require more effort to set it up and a running server or a subscription to a paid plan.