- Create a VPC: This will be the virtual network for your AWS resources.
- Create Public and Private Subnets: Distribute these across two availability zones for high availability.
- Attach an Internet Gateway to the VPC to allow communication between instances in the public subnets and the internet.
- Create Security Groups: These will act as virtual firewalls to control inbound and outbound traffic for your instances.
- Set Up Route Tables: Associate public subnets with a route table that has a route to the internet gateway. Associate private subnets with a route table that has a route to a NAT gateway.
- NAT Gateway: To allow instances in the private subnets to access the internet.
- Bastion Host: To securely connect to your instances in the private subnet.
- Application Load Balancer: For distributing incoming application traffic across multiple targets in multiple availability zones.
- Launch EC2 Instances: Place web servers and database servers in private subnets.
- Configure Instances: Use the following script to install and host your static website.
- Register Domain with Route 53: Use AWS Route 53 to register your domain and create DNS records.
- Use the EC2 Instance to Host the Website: Deploy your static HTML web app on the EC2 instance.
Here’s the script provided for deploying the web app on an EC2 instance:
#!/bin/bash
sudo su
yum update -y
yum install -y httpd
cd /var/www/html
wget https://github.com/aeezsaul/mole-site1/raw/main/mole.zip
unzip mole.zip
cp -r /var/www/html/mole-main/* /var/www/html
rm -rf mole.zip mole-main
systemctl enable httpd
systemctl start httpd
- Switch to Super User:
sudo su
- Update System Packages:
yum update -y
- Install Apache Web Server:
yum install -y httpd
- Navigate to Web Directory:
cd /var/www/html
- Download the Website Files:
wget https://github.com/aeezsaul/mole-site1/raw/main/mole.zip
- Unzip the Downloaded Files:
unzip mole.zip
- Move Files to Web Directory:
cp -r /var/www/html/mole-main/* /var/www/html
- Clean Up:
rm -rf mole.zip mole-main
- Start Apache Web Server:
systemctl start httpd
- Enable Apache to Start on Boot:
systemctl enable httpd
Once your website is running successfully on the EC2 instance:
- Create an Image: Use the AWS Management Console or AWS CLI to create an Amazon Machine Image (AMI) from your configured EC2 instance. This AMI can be used to launch new instances with the same configuration.
- Configure Auto Scaling Group: Set up an auto scaling group using the AMI to ensure your website scales based on traffic.
- Attach the Auto Scaling Group to the Load Balancer: Ensure your load balancer distributes incoming traffic across multiple instances.
- Test your setup: Make sure the website is accessible and functioning correctly.
- Monitor and Maintain: Use AWS CloudWatch and other monitoring tools to keep track of your website’s performance and health.