TLDR: In this blog post, we explore a live demonstration on how to deploy a static website using AWS services. The session covers creating a GitHub repository, launching an EC2 instance, and setting up an Apache web server, making it accessible to the public. This guide is perfect for beginners looking to understand cloud computing and web deployment.
In this blog post, we will walk through a live demonstration on how to deploy a static website using Amazon Web Services (AWS). This session is designed for beginners and covers essential concepts such as creating a GitHub repository, launching an EC2 instance, and setting up an Apache web server to make the website publicly accessible.
Overview of the Session
Varun begins by expressing gratitude for the opportunity to share his knowledge. He emphasizes the importance of understanding cloud computing and how easy it is to deploy a website with just a few clicks. The session aims to consolidate the knowledge gained from previous discussions on GitHub, cloud computing, and web hosting.
Step 1: Preparing the Website
Varun starts by showcasing the static website he created for the demonstration. The website consists of an index.html
file and several other assets stored locally. The first step is to push all these files to a GitHub repository.
Creating a GitHub Repository
Log into GitHub and create a new repository named "AWS demo".
Initialize a Git repository in the local folder containing the website files using the command
git init
.Add all files to the staging area with
git add .
.Commit the changes with a message, e.g., "added all the files".
Push the changes to the GitHub repository using
git push -u origin main
.
Step 2: Launching an EC2 Instance
With the website files now on GitHub, Varun moves on to AWS to launch an EC2 instance, which will host the website.
Setting Up AWS EC2
Create an AWS account if you don't have one. AWS offers free credits for new users.
Navigate to the EC2 dashboard and select the option to launch a new instance.
Choose an Amazon Machine Image (AMI). Varun selects Red Hat Linux for this demonstration.
Select the instance type. The T2 micro instance is chosen for its eligibility under the free tier.
Create a key pair for secure access to the instance. Varun names it "demo" and downloads the
.pem
file.Configure network settings. Ensure that the instance has a public IP address assigned.
Set up security groups to allow SSH and HTTP traffic. Varun explains the importance of restricting SSH access to specific IP addresses for security.
Launch the instance and wait for it to initialize.
Step 3: Connecting to the EC2 Instance
Once the EC2 instance is running, Varun demonstrates how to connect to it using SSH.
Connecting via SSH
Open a terminal on your local machine.
Change permissions of the downloaded
.pem
file to ensure it is not publicly viewable usingchmod 400 demo.pem
.Connect to the instance using the command:
ssh -i demo.pem ec2-user@<public-ip-address>
Switch to the root user to perform administrative tasks using
sudo su -
.
Step 4: Installing Required Software
With access to the EC2 instance, Varun installs necessary software to host the website.
Installing Apache Web Server
Update the system using
yum update -y
.Install Git using
yum install git -y
.Install Apache using
yum install httpd -y
.Start the Apache service with
systemctl start httpd
.Enable the service to start on boot using
systemctl enable httpd
.
Step 5: Deploying the Website
Now that the web server is running, Varun copies the website files from GitHub to the appropriate directory on the server.
Copying Files to the Web Server
Clone the GitHub repository to the EC2 instance using:
git clone <repository-url>
Copy the website files to the Apache directory (
/var/www/html
) using thecp
command.For files:
cp index.html /var/www/html/
For directories:
cp -r assets /var/www/html/
Verify the files are in the correct location by listing the contents of the directory.
Step 6: Accessing the Website
With the files in place, demonstrates how to access the website from a browser.
Testing the Website
Open a web browser and enter the public IP address of the EC2 instance.
If the website does not load, ensure that the Apache server is running and that the correct HTTP traffic is allowed through the security group.
Refresh the page to see the deployed website.
Conclusion
Varun concludes the session by highlighting the simplicity of deploying a website on AWS. He encourages beginners to experiment with different types of applications, including dynamic websites using Node.js or Python. The session serves as a comprehensive guide for anyone looking to understand cloud computing and web deployment.