Java Application on AWS 3-Tier Architecture
terraform -chdir=terraform fmt -checkOverview
Section titled “Overview”Provisioning EC2/RDS/VPC resources can create ongoing AWS spend.
What You Will Build
Section titled “What You Will Build”Architecture Diagram
Section titled “Architecture Diagram”Prerequisites
Section titled “Prerequisites”- Install or review: Java, Spring Boot, Maven, Tomcat, Nginx, MySQL, AWS, Terraform.
- Use your own cloud account credentials and keep them out of commits.
- This project expects cloud resources, so verify budget alerts and cleanup first.
- Open the safety guide before running commands that create infrastructure.
Credentials And Cost Warning
Section titled “Credentials And Cost Warning”Cost risk is high. Cloud target: AWS. Cloud credentials needed: Yes. Always use your own account, never commit secrets, and confirm cleanup before creating paid infrastructure.
Step-By-Step Lab
Section titled “Step-By-Step Lab”Use this flow before you run commands:
- Read the cost and credential warning above.
- Review the validation, troubleshooting, cleanup, and portfolio proof sections below.
- Follow the original project guide preserved near the bottom of this page.
- Return to the validation and cleanup checks before you capture portfolio evidence.
Validation Checks
Section titled “Validation Checks”Run the project validation command before and after meaningful changes:
terraform -chdir=terraform fmt -checkTroubleshooting
Section titled “Troubleshooting”- Run
terraform -chdir=terraform fmt -checkfirst so local tooling issues are visible early. - If a command fails, check tool versions, working directory, and required environment variables.
- For cloud failures, confirm account identity, region, quotas, and least-privilege IAM.
Cleanup
Section titled “Cleanup”Cleanup is available or expected for this lab. Use the cleanup or destroy steps in the guide below, then confirm that local clusters, containers, cloud resources, buckets, state files, and CI secrets are no longer active.
Portfolio Proof
Section titled “Portfolio Proof”- Validation command output:
terraform -chdir=terraform fmt -check - Screenshot or terminal proof: Plan/apply evidence plus destroy proof
- Notes explaining what changed, what failed, and how you fixed it
- Cleanup evidence, especially for cloud or Kubernetes resources
Original Project Guide
Section titled “Original Project Guide”The original README content is preserved here for lab-specific commands and context. Headings are intentionally demoted so the page outline stays focused on the standard lab flow.
TABLE OF CONTENTS
Section titled “TABLE OF CONTENTS”- Goal
- Pre-Requisites
- Pre-Deployment
- VPC Deployment
- Maven (Build)
- 3-Tier Architecture
- Application Deployment
- Post-Deployment
- Validation
Goal of this project is to deploy scalable, highly available and secured Java application on 3-tier architecture and provide application access to the end users from public internet.
🛡️ 2026 DevSecOps Enhancements (What You Will Learn)
Section titled “🛡️ 2026 DevSecOps Enhancements (What You Will Learn)”This project has been upgraded to meet 2026 Cloud Security and DevSecOps standards. As you follow the deployment steps, pay attention to the following modern architectural patterns implemented within the Terraform code:
- Zero-Trust Networking (Network Segmentation): We explicitly dropped
0.0.0.0/0(open internet) rules from internal database and application tiers. Security Groups now strictly enforce traffic only from verified Load Balancers and Bastions. - Principle of Least Privilege (IAM): We destroyed overarching
s3:*wildcards, replacing them with granular, whitelisted API actions (s3:GetObject,s3:PutObect). - Automated Infrastructure Scanning: The project structure has been adapted so external scanners like Checkov/tfsec can easily identify misconfigurations before deployment.
Pre-Requisites
Section titled “Pre-Requisites”- Create AWS Free Tier account
- Create GitHub account and create repository to keep this Java Source Code
- Migrate Java Source Code to your own GitHub repository
- Create account in Sonarcloud.
- Create account in Jfrog cloud.
- Security Mandate: Find your public IP address and replace
YOUR_IP_ADDRESS/32interraform/bastion.tf,terraform/apache-ec2.tf, andterraform/nginx-ec2.tfbefore deploying.
Pre-Deployment
Section titled “Pre-Deployment”- Create Global AMI
- AWS CLI
- Cloudwatch agent
- Install AWS SSM agent
- Create Golden AMI using Global AMI for Nginx application
- Install Nginx
- Push custom memory metrics to Cloudwatch.
- Create Golden AMI using Global AMI for Apache Tomcat application
- Install Apache Tomcat
- Configure Tomcat as Systemd service
- Install JDK 11
- Push custom memory metrics to Cloudwatch.
- Create Golden AMI using Global AMI for Apache Maven Build Tool
- Install Apache Maven
- Install Git
- Install JDK 11
- Update Maven Home to the system PATH environment variable
VPC Deployment
Section titled “VPC Deployment”Deploy AWS Infrastructure resources as shown in the above architecture.
VPC (Network Setup)
Section titled “VPC (Network Setup)”- Build VPC network ( 192.168.0.0/16 ) for Bastion Host deployment as per the architecture shown above.
- Build VPC network ( 172.32.0.0/16 ) for deploying Highly Available and Auto Scalable application servers as per the architecture shown above.
- Create NAT Gateway in Public Subnet and update Private Subnet associated Route Table accordingly to route the default traffic to NAT for outbound internet connection.
- Create Transit Gateway and associate both VPCs to the Transit Gateway for private communication.
- Create Internet Gateway for each VPC and update Public Subnet associated Route Table accordingly to route the default traffic to IGW for inbound/outbound internet connection.
Bastion
Section titled “Bastion”- Deploy Bastion Host in the Public Subnet with EIP associated.
- Create Security Group allowing port 22 from public internet
Maven (Build)
Section titled “Maven (Build)”- Create EC2 instance using Maven Golden AMI
- Clone GitHub repository to VSCode and update the pom.xml with Sonar and JFROG deployment details.
- Add settings.xml file to the root folder of the repository with the JFROG credentials and JFROG repo to resolve the dependencies.
- Update application.properties file with JDBC connection string to authenticate with MySQL.
- Push the code changes to feature branch of GitHub repository
- Raise Pull Request to approve the PR and Merge the changes to Master branch.
- Login to EC2 instance and clone the GitHub repository
- Build the source code using maven arguments “-s settings.xml”
- Integrate Maven build with Sonar Cloud and generate analysis dashboard with default Quality Gate profile.
3-Tier Architecture
Section titled “3-Tier Architecture”Database (RDS)
Section titled “Database (RDS)”- Deploy Multi-AZ MySQL RDS instance into private subnets
- Create Security Group allowing port 3306 from App instances and from Bastion Host.
Tomcat (Backend)
Section titled “Tomcat (Backend)”- Create private facing Network Load Balancer and Target Group.
- Create Launch Configuration with below configuration.
- Tomcat Golden AMI
- User Data to deploy .war artifact from JFROG into webapps folder.
- Security Group allowing Port 22 from Bastion Host and Port 8080 from private NLB.
- Create Auto Scaling Group
Nginx (Frontend)
Section titled “Nginx (Frontend)”- Create public facing Network Load Balancer and Target Group.
- Create Launch Configuration with below configuration
- Nginx Golden AMI
- User Data to update proxy_pass rules in nginx.conf file and reload nginx service.
- Security Group allowing Port 22 from Bastion Host and Port 80 from Public NLB.
- Create Auto Scaling Group
Application Deployment
Section titled “Application Deployment”- Artifact deployment taken care by User Data script during Application tier EC2 instance launch process.
- Login to MySQL database from Application Server using MySQL CLI client and create database and table schema to store the user login data (Instructions are update in README.md file in the GitHub repo)
Post-Deployment
Section titled “Post-Deployment”- Configure Cronjob to push the Tomcat Application log data to S3 bucket and also rotate the log data to remove the log data on the server after the data pushed to S3 Bucket.
- Configure Cloudwatch alarms to send E-Mail notification when database connections are more than 100 threshold.
Validation
Section titled “Validation”- Verify you as an administrator able to login to EC2 instances from session manager & from Bastion Host.
- Verify if you as an end user able to access application from public internet browser.
Hit the Star! ⭐
Section titled “Hit the Star! ⭐”If you are planning to use this repo for learning, please hit the star. Thanks!
Source Files On GitHub
Section titled “Source Files On GitHub”The full learning flow stays on this page. Open GitHub only when a step asks you to inspect code, fork the lab, or download source assets.