Host Low-cost Private Maven Repository on AWS

Introduction

Prerequisites

  • Running AWS EC2 instance with root access or a user with Sudo access. I am using t2.micro instance with Amazon Linux for this tutorial
  • The EC2 instance has a Security Group attached to it allowing access to SSH port 22and TCP port 8080from your machine/subnet CIDR
  • The EC2 instance should have an IAM role which has read-write permissions to access S3 buckets in your AWS account
  • Git is installed on the EC2 instance

Steps

Installation of Apache Archiva

  1. SSH into your EC2 instance and run the following commands to create installation directory and download Archiva stand-alone distribution:
$ mkdir archiva && cd archiva
$ wget http://apache.mirrors.pair.com/archiva/2.2.4/binaries/apache-archiva-2.2.4-bin.tar.gz
$ tar -zxvf apache-archiva-2.2.4-bin.tar.gz
$ cd apache-archiva-2.2.4
$ ./bin/archiva console
Image-1: Apache Archiva Web Console
http://<YOUR_EC2_PUBLIC_IPV4_ADDRESS>:8080/repository/internal/junit/junit/3.8.1/junit-3.8.1.jar
$ tree ~/archiva/apache-archiva-2.2.4/repositories/internal
.
└── junit
└── junit
├── 3.8.1
│ ├── junit-3.8.1.jar
│ ├── junit-3.8.1.jar.md5
│ ├── junit-3.8.1.jar.sha1
│ ├── junit-3.8.1.pom
│ ├── junit-3.8.1.pom.md5
│ ├── junit-3.8.1.pom.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
├── maven-metadata.xml
├── maven-metadata.xml.md5
└── maven-metadata.xml.sha1
3 directories, 12 files
Image-2: Override Directory and Index Directory paths

Mount S3 bucket on EC2 Linux Instance

Steps

  1. Create a private S3 bucket named my-archiva-repo or some unique name
  2. Create an AWS IAM role with S3 Full Access Permission by navigating to AWS Menu -> Your AWS Account Name -> My Security Credentials -> Users . If you have the user created already, ensure that it has S3 Full Access permission.
  3. Create S3FS password file & set owner only permissions. Make sure to replace ACCESS_KEY_ID and SECRET_ACCESS_KEY with your IAM user’s keys
$ echo ACCESS_KEY_ID:SECRET_ACCESS_KEY > ${HOME}/.passwd-s3fs
$ chmod 600 ${HOME}/.passwd-s3fs
$ mkdir ~/my-archiva-repo$ s3fs my-archiva-repo -o use_cache=/tmp -o allow_other -o uid=1001 -o mp_umask=002 -o multireq_max=5 ~/my-archiva-repo
s3fs#my-archiva-repo ~/my-archiva-repo fuse _netdev,allow_other 0 0
my-archiva-repo ~/my-archiva-repo fuse.s3fs _netdev,allow_other 0 0

Update Archiva Directory settings

Image-3: Update Repository Directory Path

Verify Archiva Repository Path changes

$ tree ~/my-archiva-repo/
/home/ec2-user/my-archiva-repo/
└── repositories
└── internal
└── junit
└── junit
├── 3.8.1
│ ├── junit-3.8.1.jar
│ ├── junit-3.8.1.jar.md5
│ ├── junit-3.8.1.jar.sha1
│ ├── junit-3.8.1.pom
│ ├── junit-3.8.1.pom.md5
│ ├── junit-3.8.1.pom.sha1
│ ├── maven-metadata.xml
│ ├── maven-metadata.xml.md5
│ └── maven-metadata.xml.sha1
├── maven-metadata.xml
├── maven-metadata.xml.md5
└── maven-metadata.xml.sha1
5 directories, 12 files
Image-4: S3 Bucket Contents

Concluding Thoughts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store