DEV Community

Cover image for From Zero to Cloud: Building Your First Java Web App on AWS with VS Code
Adesola Kehinde
Adesola Kehinde

Posted on

From Zero to Cloud: Building Your First Java Web App on AWS with VS Code

This project is part one of a series of DevOps projects where I'm building a CI/CD pipeline! I'll be working on the next project in a few days to expand what I've learnt.


💡 Why I Did This Project

I wanted to learn how to set up the foundation of a CI/CD pipeline. This project walked me through the process of launching an EC2 instance and using it to build and edit a web app — completely in the cloud.


🟢 Step 1: Launch EC2 Instance

We started this project by launching an EC2 instance because EC2 instances are like virtual computers that live in the cloud. We want our web app to live entirely in the cloud, so we are launching an EC2 instance to even develop our web app's code.

Image description

🔑 Step 2: Key Pair

A key pair is a mechanism for us to access EC2 instances. I created a key pair that AWS stores the public part of, and I downloaded the private key. AWS will authenticate this private key when I connect later.

Once I set up my key pair, AWS automatically downloaded a .pem file to my computer.

Image description

🧠 Step 3: Understanding SSH

SSH is a secure way to remotely access another computer. I enabled SSH so that I could access my EC2 instance safely from my local computer.

🛠️ Step 4: Install VS Code

VS Code is a lightweight and powerful source code editor.

I installed VS Code to easily navigate and edit code inside my EC2 instance.

Image description


💻 Step 5: Terminal Setup + Key Permissions

I used the terminal to interact with my EC2 instance.

A terminal is a tool to run shell commands. The first command I ran for this project is cd ~/Desktop/Devops-keys.

I also updated my private key's permissions by running:

chmod 400 network-keypair.pem
Enter fullscreen mode Exit fullscreen mode

Image description


🌐 Step 6: Connect to EC2

We're connecting to our EC2 instance so we can run code and install tools directly in the cloud.

To connect to my EC2 instance, I ran the command:

ssh -i "network-keypair.pem" ec2-user@<my-ec2-ipv4-dns>
Enter fullscreen mode Exit fullscreen mode

Image description
A server's IPv4 DNS is the address I used to connect to the EC2 instance from my local machine.


🔧 Step 7: Install Java + Maven

We're installing tools to help us build and run Java-based web apps.

Apache Maven is a build automation tool used to manage Java projects. Maven is required in this project because it simplifies building and managing our Java web app.

Java is a programming language. Java is required in this project because our web app is written in Java.


🏗️ Step 8: Generate the App

In this step, I’m running a Maven command that generates the structure of a new Java web app — like creating the skeleton of the website.

I generated a Java web app using the command:

mvn archetype:generate ...
Enter fullscreen mode Exit fullscreen mode

Image description


👁️ Step 9: View and Edit in VS Code

Even though I’m connected with SSH in the terminal, I want all of VS Code’s IDE features, so I installed Remote - SSH.

I installed Remote - SSH, which is a VS Code extension that lets me edit remote files. I installed it to open and manage my EC2 files like they’re local.

Configuration details required to set up a remote connection include the name of my EC2, its IP, and the private key path — so that VS Code can connect securely.

Using VS Code’s file explorer, I could see all the folders and files of the Java project.

Two of the project folders created by Maven are src and webapp, which contain the source code and web assets of the Java web app.

index.jsp is the home page of the web app. I edited index.jsp by adding my name to personalize the page.

Image description


✅ Final Thoughts

Services I used were EC2, SSH, VS Code, Maven, Java.

Key concepts I learnt include SSH, cloud-based development, Maven builds, and managing keys.


❗ One Thing I Didn’t Expect

I didn’t expect to learn so much about SSH and permissions! It was a fun challenge.

This project took me approximately 2 hours. The most challenging part was connecting and verifying the keys. It was most rewarding to see my web app running in the cloud!


🎯 Did It Meet My Goals?

Yes — I wanted to deploy code entirely from the cloud, and this project got me there.


Thanks for reading! 🚀 Stay tuned for the next DevOps adventure.

Top comments (0)