From Code to Cloud: Deploying Maven Projects on AWS
“The science of today is the technology of tomorrow.” — Edward Teller
To deploy your Maven project on an AWS server the following steps should be performed:
- Creating an AWS instance
- Connecting your AWS instance with SSH
- Building your project
- Uploading the built artifact to the AWS server.
Creating an AWS Instance
- First of all, make sure you have an AWS account
- Open the AWS console. Click on Service and Select “EC2”
3. Click on Launch instance
4. Enter the name of your instance and Select the required AMI(Amazon Machine Index), Instance type.
5. Enter the name for key-pair and click on “Create a new key pair” and download the file.
6. Check all three boxes under Network Settings.
Select your required Storage configuration and click on Launch Instance.
Connecting your AWS instance to SSH
- Open your SSH.
- Change the permission to the key-pair that you downloaded earlier:
sudo chmod 440 <key_pair_file_path>
3. Go to your AWS Instance, select it and click on CONNECT
4. Go to SSH client
and copy the example command at the bottom.
5. Run this command in the directory containing your key-pair file.
You have successfully gained access to your server!!
Building your Project
On your local host:
- Update your package lists using the following command
sudo apt-get update
2. Install Java
sudo apt install java-1.8.0-openjdk-devel
3. Install Maven
sudo apt install maven
4. Clone your project’s git repository
git clone repo_url
5. Go to the root directory of your project and Build the project using the following command:
6. After a successful build a target
directory will be created. Go to target
and you will find a .jar
file.
7. This .jar
is your Artifact.
Transferring Artifact
- Make sure you have
scp
installed on your local host. If not, run this:
sudo apt-get install openssh-client
To upload the Artifact file enter:
scp -i <your_key.pem> <artifact_path> <ec2-username>@<your-aws-host-ip-or-dns>:</path/to/destination/directory/>
If this command is hard to follow then paste the “Example command” we copied while connecting our AWS to the SSH client. In that command enter the artifact file path after the key-pair file and at last enter :
followed by the destination you want for your atifact in the server. ex: /home/ubuntu