Day-43-devops

Deploying a Website on AWS: A Step-by-Step Guide

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

  1. Log into GitHub and create a new repository named "AWS demo".

  2. Initialize a Git repository in the local folder containing the website files using the command git init.

  3. Add all files to the staging area with git add ..

  4. Commit the changes with a message, e.g., "added all the files".

  5. 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

  1. Create an AWS account if you don't have one. AWS offers free credits for new users.

  2. Navigate to the EC2 dashboard and select the option to launch a new instance.

  3. Choose an Amazon Machine Image (AMI). Varun selects Red Hat Linux for this demonstration.

  4. Select the instance type. The T2 micro instance is chosen for its eligibility under the free tier.

  5. Create a key pair for secure access to the instance. Varun names it "demo" and downloads the .pem file.

  6. Configure network settings. Ensure that the instance has a public IP address assigned.

  7. Set up security groups to allow SSH and HTTP traffic. Varun explains the importance of restricting SSH access to specific IP addresses for security.

  8. 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

  1. Open a terminal on your local machine.

  2. Change permissions of the downloaded .pem file to ensure it is not publicly viewable using chmod 400 demo.pem.

  3. Connect to the instance using the command:

     ssh -i demo.pem ec2-user@<public-ip-address>
    
  4. 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

  1. Update the system using yum update -y.

  2. Install Git using yum install git -y.

  3. Install Apache using yum install httpd -y.

  4. Start the Apache service with systemctl start httpd.

  5. 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

  1. Clone the GitHub repository to the EC2 instance using:

     git clone <repository-url>
    
  2. Copy the website files to the Apache directory (/var/www/html) using the cp command.

    • For files: cp index.html /var/www/html/

    • For directories: cp -r assets /var/www/html/

  3. 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

  1. Open a web browser and enter the public IP address of the EC2 instance.

  2. 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.

  3. 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.