Deploy Java Application On Aws 3 Tier Architecture
August 2024 (461 Words, 3 Minutes)
STEP ONE: Global AMI
We are going to create a Global AMI with the following installations
- AWS CLI
- Cloudwatch agent
- Install AWS SSM agent
Go to AWS Console, Search for EC2 on the searchbar and click on instances. Launch an instance with default settings. Make sure to create a key pair.
SSH Into the instance to install
- AWS CLI
- Cloudwatch agent
- Install AWS SSM agent
Install AWS CLI
Navigate to the Official AWS documentation and follow the instructions given to install AWS CLI depending on the operating system you are using
How to Install or update to the latest version of the AWS CLI
Install Cloudwatch agent
Navigate to the Official AWS documentation and follow the instructions given to install CloudWatch Agent
How to Install the CloudWatch agent
Install AWS SSM agent
Navigate to the Official AWS documentation and follow the instructions given to install AWS SSM agent
How to Manually install and uninstall SSM Agent on EC2 instances for Linux
Creating AMI from the instance
Navigate back to the instance dashboard and click on the instance. Go to actions then images and templates then to create image
STEP TWO: Create Golden AMI using Global AMI for Nginx application
Launch an instance using the Global AMI we created, by navigating to AMIs selecting the Global AMI then selecting Launch instance from AMI
SSH into the instance so as to:
- Install Nginx
- Push custom memory metrics to Cloudwatch
Install Nginx
Navigate to the Official Nginx Website and check on the documentation to install Nginx on the Instance
How to Install nginx on Amazon Linux 2023
Push custom memory metrics to Cloudwatch
How to push custom metrics to CloudWatch
You can use SSM to install the CloudWatch agent then use the wizard to write the configuration file
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
After you have finished with the configuration, start the cloudwatch agent with
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:configuration-file-path -s
Your configuration file path is listed after finishing the configuration with the wizard
STEP THREE: Create Golden AMI using Global AMI for Apache Tomcat Application
Use the AMI created to launch another instance.
SSH into the instance so as to:
- Install Apache Tomcat
- Configure Tomcat as Systemd service
- Install JDK 11
Install Apache Tomcat
You can use the instructions from the official AWS Website
To Configre Tomcat as Systemd service Step1: Create the systemd file: nano /etc/systemd/system/tomcat.service Step2: Copy
[Unit]
Description=Apache Tomcat
After=network.target
[Service]
Type=forking
User=tomcat10
Group=tomcat10
ExecStart=/opt/apache-tomcat-10.1.28/bin/startup.sh
ExecStop=/opt/apache-tomcat-10.1.28/bin/shutdown.sh
- Make sure you edit that and use your installation folder
Step3: Add a user
useradd tomcat10
Step4: Change user passwordpasswd tomcat10
Step5: Run the cmdsudo systemctl daemon-reload
From now on, you can use following commands to start or stop the tomcat:
sudo service tomcat start
sudo service tomcat stop
Install JDK 11
How to install Java 11 on Amazon Linux 2023
Push custom memory metrics to Cloudwatch
How to push custom metrics to CloudWatch
You can use SSM to install the CloudWatch agent then use the wizard to write the configuration file
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
After you have finished with the configuration, start the cloudwatch agent with
sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:configuration-file-path -s
Your configuration file path is listed after finishing the configuration with the wizard