AWS Static web site deployment

Goal

Deploy HTML based static website on Amazon EC2 instance and configure logging, monitoring, alerts.  This project hosting static web application on Apache Web Server to serve the web pages to internet clients. 

Pre-Requisites

  1. You must be having an AWS account to create infrastructure resources on AWS cloud.
  2. Source Code

Pre-Deployment

Customize the application dependencies mentioned below on AWS EC2 instance and create the Golden AMI.

  1. AWS CLI
  2. Install Apache Web Server
  3. Install Git
  4. Configure Apache to start automatically after the instance reboot.

Deployment

Infrastructure Setup

  1. Create Security Group allowing port 22 from custom IP source ( Your workstation IP ) and port 80 from public.
  2. Create Key-Pair and download the private key.
  3. Create t2.micro type EC2 instance using Golden AMI. 
  4. Create Elastic IP and associate the IP to EC2 instance.
  5. Create GP2 type EBS volume named /dev/xvdb of size 5GB in same AZ where EC2 was created.
  6. Attach EBS volume to EC2 instance.
  7. Create Route53 hosted zone with your domain name and configure A record pointing to the EC2 EIP.
  8. Create private S3 bucket and enable versioning.

Application Setup

  1. Create File System on xvdb volume and mount it on /var/www/html directory. 
  2. Use Git commands and clone the source code from Bit Bucket repository provided in the pre-requisites.  ()
  3. Deploy the source code into web server document root folder – /var/www/html

Post-Deployment

  1. Configure Cloudwatch agent to monitor Memory utilization of EC2 instance.
  2. Create Cloudwatch Dashboard to monitor CPU & Memory metrics of the EC2 instance.
  3. Configure SNS topic and subscribe e-mail to the Topic.
  4. Configure Cloudwatch alarm with 1 data point and 5 minutes interval rate to notify to SNS topic when average CPU utilization is greater than 80% threshold.
  5. Configure Cloudwatch alarm with 1 data point and 5 minutes interval rate to notify to SNS topic when average Memory utilization is greater than 60% threshold. 
  6. Use AWS CLI commands to push webserver logs to S3 bucket.
  7. Configure S3 life cycle rules to transit previous version objects to Glacier after 30 days and delete the objects after 90 days of object creation date.

Validation

  1. Verify if you are able to access the web application from internet browser. 

Kindly leave comment below with your experience with this simple project. 

© Edwiki Trainings – Click HERE If you are interested to learn more on Cloud & DevOps stack.

6 Shares:
21 comments
    1. I have installed the cloud watch agent in the ec2 machine and created the custom metrics for memory monitoring. please let me know if this is correct

      1. That was also what i did, installing the agent, configuring it using aws cli config wizard and creating the dashborad using the memory metric from the cwagent namespace in the cloudwatch console

    2. Here is a summarized guide on how to obtain memory metrics from ec2 using the cloudwatch agent.
      https://www.scalyr.com/blog/ec2-memory-usage/
      If you need more info on how to set it up, you can review the aws documentation for extensive details.
      https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Install-CloudWatch-Agent.html

      In short these are my steps on the Ec2 instance to enable and configure the cloudwatch agent and simulate a memory spike. I used the wizard instead of manually editing the config.json file
      yum install amazon-cloudwatch-agent -y
      /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-config-wizard
      systemctl status amazon-cloudwatch-agent.service
      simulated a memoy spike using this command
      stress –vm-bytes $(awk ‘/MemAvailable/{printf “%d\n”, $2 * 0.9;}’ < /proc/meminfo)k –vm-keep -m 1

      1. I forgot to add you need to start the cloudwatch agent
        /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a fetch-config -m ec2 -c file:/opt/aws/amazon-cloudwatch-agent/bin/config.json -s

  1. Completed the above exercise by taking one domain in freenom website & SUCCESSFULLY hosted by using awsnameservers AND ABLE TO access the web application from internet browser.

  2. I have completed the assignment and learnt to be more comfortable using cloudwatch agent, iam roles and aws cli to copy and sync files to s3

  3. I completed 75% of the assignment but pending with following tasks.

    Please explain how to configure cloud watch agent to monitor memory utilisation and also explain How to set up AWS CLI and how it helps to push the webserver logs to S3 bucket

    1. Please check the comment added by Yemi with all the steps that you need to follow to monitor EC2 instance memory metric.
      Thank You, Yemi for the details.

  4. Completed the given assignment and I am able to access the webserver through the registered domain name
    – created volume of 5gb and attached to EC2 instance.
    – installed cloudwatchagent for creating memory based metrics
    – created dashboard for memory and cpu metrics
    – pushed webserver logs which are access_log and error_log to s3 bucket using cli
    – created lifecycle for the objects in s3 which transits data to glacier after 30 days and expires after 90 days

  5. Hey PR Thanks for creating such wonderful exercise covering multiple AWS services. The Post deployment was tricky for me. However, I’ve completed it with ease, Shout out to yemi for helping the fellow mates. I’m looking forward to more of such intriguing exercises.

    I would request you to create more challenging and complex exercises(covering more use cases of the services) and sub challenges.

  6. Thanks PR. I completed the assignment all the steps except below step.
    Use AWS CLI commands to push webserver logs to S3 bucket.
    The webserver log will update very frequently and it need to PUsh S3 bucket. I am searching which scenario suitable for this(Cron job for aws s3 cp)
    Please let us know if you have any other solution for this.

  7. It was challenging but with web research i was able to do it. the only part i did not do on the cli was pushing webserver logs to the s3 bucket. i did it on the s3 and cloudwatch platform.

  8. Create File System on xvdb volume and mount it on /var/www/html directory.
    here how to mount xvdb file system to /var/www/html. i mounted it xvdb but after this i unable to deploy code in /var/www/html. its file or directory not empty. please tell me

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like