This project demonstrates how to host a static HTML web app on AWS using various AWS services and resources. The infrastructure is designed for high availability, fault tolerance, and scalability.
The infrastructure for hosting the static website includes the following components:
- Virtual Private Cloud (VPC): Configured with both public and private subnets across two different availability zones.
- Internet Gateway: Facilitates connectivity between VPC instances and the wider Internet.
- Security Groups: Act as a network firewall mechanism.
- Multiple Availability Zones: Enhance system reliability and fault tolerance.
- Public Subnets: Used for infrastructure components like the NAT Gateway and Application Load Balancer.
- EC2 Instance Connect Endpoint: Allows secure connections to assets within both public and private subnets.
- Private Subnets: Where web servers (EC2 instances) are placed for enhanced security.
- NAT Gateway: Enables instances in both private Application and Data subnets to access the Internet.
- EC2 Instances: Host the website.
- Application Load Balancer: Distributes web traffic evenly to an Auto Scaling Group of EC2 instances across multiple Availability Zones.
- Auto Scaling Group: Automatically manages EC2 instances, ensuring website availability, scalability, fault tolerance, and elasticity.
- GitHub: Stores web files for version control and collaboration.
- Certificate Manager: Secures application communications.
- Simple Notification Service (SNS): Alerts about activities within the Auto Scaling Group.
- Route 53: Registers the domain name and sets up a DNS record.
Follow these steps to deploy the static website on AWS:
- AWS account
- Domain name registered (using Route 53 or another registrar)
- GitHub repository containing your static website files
- Create a VPC with public and private subnets in two availability zones.
- Deploy an Internet Gateway and attach it to the VPC.
- Set up Security Groups to control inbound and outbound traffic to your instances.
- Deploy a NAT Gateway in the public subnet to allow instances in private subnets to access the Internet.
- Launch EC2 Instances in the private subnet to host your website.
- Set up an Application Load Balancer in the public subnet and configure it to distribute traffic to the EC2 instances.
- Configure an Auto Scaling Group to manage the EC2 instances automatically.
- Use Certificate Manager to create and manage SSL/TLS certificates for your domain.
- Set up SNS for notifications about Auto Scaling Group activities.
- Register your domain and configure Route 53 to route traffic to your Application Load Balancer.
Use the following user data script to configure your EC2 instances:
#!/bin/bash
# Switch to the root user to gain full administrative privileges
sudo su
# Update all installed packages to their latest versions
yum update -y
# Install Apache HTTP Server
yum install -y httpd
# Change the current working directory to the Apache web root
cd /var/www/html
# Install Git
yum install git -y
# Clone the project GitHub repository to the current directory
git clone https://github.com/BigAust/aws-static-website.git
# Copy all files, including hidden ones, from the cloned repository to the Apache web root
cp -R host-a-static-website-on-aws/. /var/www/html/
# Remove the cloned repository directory to clean up unnecessary files
rm -rf host-a-static-website-on-aws
# Enable the Apache HTTP Server to start automatically at system boot
systemctl enable httpd
# Start the Apache HTTP Server to serve web content
systemctl start httpd