Building and Scaling Web Applications on AWS: A Step-by-Step Guide
Day 47 : #90DaysOfDevOps Challange
Task-01: Launch an EC2 instance, install a web server, and deploy a simple web application
Launch an EC2 instance using the AWS Management Console:
Log in to the AWS Management Console.
Open the EC2 service.
Click on "Launch Instance" to start the instance launch wizard.
Select "Ubuntu Server 18.04 LTS" or the desired version.
Select an instance type - Choose "t2.micro" for this example.
Configure instance details:
Number of instances - Set to 1.
Network - Choose the desired VPC and subnet.
Auto-assign Public IP - Set to "Enable".
Add storage as per your requirements.
Add tags (optional) for better identification of the instance.
Configure security groups:
Create a new security group or select an existing one.
Allow inbound SSH (port 22) from your IP or a specific IP range.
Review your configuration and click "Launch" to start the instance.
Select an existing key pair or create a new one to connect to the instance using SSH. Make sure to download the private key file (e.g.,
key.pem
) and keep it secure.
Connect to the EC2 instance using SSH:
Use the SSH command to connect to the EC2 instance:
ssh -i /path/to/key.pem ubuntu@<public-ip>
Replace
/path/to/key.pem
with the actual path to your private key file and<public-ip>
with the public IP of your EC2 instance.
Install a web server (Apache) on the EC2 instance:
Update the package manager:
sudo apt update
Install Apache:
sudo apt install apache2 -y
Start the Apache service:
sudo systemctl start apache2
Enable the Apache service to start on boot:
sudo systemctl enable apache2
Deploy a simple web application:
Copy your web application files to the appropriate directory for the web server to serve them. In this example, we'll assume your web application files are in a directory named
my-web-app
.sudo cp -R /path/to/my-web-app/* /var/www/html
Replace
/path/to/my-web-app
with the actual path to your web application files.Make sure the web server has permissions to access the files:
sudo chown -R www-data:www-data /var/www/html
Verify the deployment:
Open a web browser and enter the public IP of your EC2 instance.
If the Apache default page or your web application is displayed, it means the deployment was successful.
π₯³π₯³π₯³π₯³πππππππππππππππππππWith these steps, you will be able to launch an EC2 instance, install a web server (Apache), and deploy your web application on the EC2 instance.
You can find the complete source code for the CEO Trivia Challenge web application in the GitHub repository: GitHub - Dhananjaykul/CEO-Trivia-Challenge. Feel free to explore the repository for more details and to contribute to the project.
Task-02: Create Auto Scaling Group, Monitor Performance, and Verify with AWS CLI
Create an Auto Scaling group using the AWS Management Console:
Log in to the AWS Management Console.
Navigate to the EC2 service.
Click on "Auto Scaling Groups" in the sidebar.
Click on "Create Auto Scaling group" to start the Auto Scaling group creation wizard.
Configure the launch template or launch configuration for the instances in the Auto Scaling group.
Set the desired capacity, minimum and maximum capacity limits, and other scaling policies based on your requirements.
Configure the network settings, load balancer (if applicable), and health check settings.
Review your configuration and create the Auto Scaling group.
Use Amazon CloudWatch to monitor the performance of the Auto Scaling group and EC2 instances:
Go to the CloudWatch service in the AWS Management Console.
Create alarms or configure metrics to monitor the Auto Scaling group's scaling activities, instance health, CPU utilization, or other relevant metrics.
Set up notifications to receive alerts if any issues arise with the Auto Scaling group or its instances.
Utilize CloudWatch logs and metrics to troubleshoot any performance or health-related issues.
Use the AWS CLI to view the state of the Auto Scaling group and EC2 instances:
Install and configure the AWS CLI on your local machine.
Open a terminal or command prompt.
Use the AWS CLI commands to view the state of the Auto Scaling group and the EC2 instances and verify that the correct number of instances are running.
To view the state of the Auto Scaling group:
aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <auto-scaling-group-name>
To view the state of the EC2 instances in the Auto Scaling group:
aws autoscaling describe-auto-scaling-instances --instance-ids $(aws autoscaling describe-auto-scaling-groups --auto-scaling-group-names <auto-scaling-group-name> --query "AutoScalingGroups[].Instances[].InstanceId" --output text)
Verify that the correct number of instances are running by comparing the "DesiredCapacity" and "Instances" count in the output.
These commands use the AWS CLI to fetch information about the Auto Scaling group and EC2 instances associated with it. Replace <auto-scaling-group-name>
with the actual name of your Auto Scaling group.
By following these instructions, you will be able to create an EC2 instance, install a web server, deploy a web application, monitor the instance using CloudWatch, create an Auto Scaling group, monitor its performance, and use the AWS CLI to verify the state of the Auto Scaling group and instances.