DEV Community

Revathi Joshi for AWS Community Builders

Posted on

Use Amazon CloudFront for dynamic Websites -1

What is Amazon CloudFront?

Please read my previous article Understanding Amazon CloudFront

  • Note: CloudFront allows you to configure cache control and Time-To-Live (TTL) settings, giving you control over how long content is cached at the edge locations.

  • This allows you to balance the freshness of content with cache hit rates.

  • CloudFront has features similar to dynamic site acceleration, a method used to improve online content delivery.

  • CloudFront accelerates the delivery of dynamic content by moving it closer to the user to minimize internet hops involved in retrieving the content.

  • You create a CloudFront distribution to tell CloudFront where you want content to be delivered from, and the details about how to track and manage content delivery.

Please visit my GitHub Repository for S3 articles on various topics being updated on constant basis.

Let’s get started!

I have divided this article into 3 parts for understanding this process better.

Objectives:

Part 1
1. Sign into AWS Management Console.

2. Launch two EC2 Instances my-EC2 using Bash script.

Part 2
3. Create a Target Group my-TG.

4. Create an application Load Balancer.

Part 3
5. Create the CloudFront Distribution.

6. Test the distribution.

Pre-requisites:

  • AWS user account with admin access, not a root account.

Resources Used:

Steps for implementation to this project:

1. Sign into AWS Management Console

  • Make sure you're in the N. Virginia (us-east-1) region

2. Launch two EC2 Instances my-EC2 using Bash script.

1.

Image description

2.

Image description

3. Proceed without a key pair.

Image description

4. Under Network Settings, choose Create New Security group.
  • Check the Allow SSH traffic from
  • Check the Allow HTTP traffic from the internet.
  • Check the Allow HTTPs traffic from the internet.

Image description

5. Under, User data: section, copy and paste the script to install Apache webserver and php and copy the php file from S3 bucket to the server path.
  • user data
#!/bin/bash

# Switch to the superuser to execute commands with elevated privileges
sudo su

# Update the package repository and install Apache web server (httpd) and PHP
yum update -y
yum install httpd php -y

# Start the Apache web server
systemctl start httpd

# Enable the Apache web server to start automatically on system boot
systemctl enable httpd

# Change the current directory to the web server's root directory
cd /var/www/html/

# Download the sample PHP webpage to the web server's root directory
wget https://s3.amazonaws.com/joshiawssolutions.com/index.php

# Restart the Apache web server to apply the changes and serve the PHP webpage
systemctl restart httpd
Enter fullscreen mode Exit fullscreen mode

Image description

6. Under Summary, Enter number of instances as 2.

Image description

7. Launch Instance

Image description

8. View the PHP file in the webserver:
  • 1. click on the 1st instance ID and copy the IPv4 Public IP of this instance.
http://<IPv4 public IP>/index.php

http://34.207.132.4/index.php
Enter fullscreen mode Exit fullscreen mode

Image description

  • 2. click on the 2nd instance ID and copy the IPv4 Public IP of this instance.
http://<IPv4 public IP>/index.php

http://34.227.87.42/index.php
Enter fullscreen mode Exit fullscreen mode

Image description

Top comments (0)