Use Amazon CloudFront for dynamic Websites - 3
Tags: ec2, s3, cloudfront, elasticloadbalancing
Published: 2023-09-28 14:40:10

Please read my 2 previous articles **[Use Amazon CloudFront for dynamic Websites -1](https://dev.to/aws-builders/use-amazon-cloudfront-for-dynamic-websites-1-18bo)** and **[Use Amazon CloudFront for dynamic Websites -2](https://dev.to/aws-builders/use-amazon-cloudfront-for-dynamic-websites-2-7f2)**

In this article, I am going to show you how to create the CloudFront Distribution and test it.

_**Let’s get started!**_

Please visit my **[GitHub Repository for S3 articles](https://github.com/awsmine/S3_projects)** on various topics being updated on constant basis.

## 5. Create the CloudFront Distribution.
- CloudFront is a content delivery network (CDN) that caches and serves content from multiple edge locations worldwide. 
- When you create a CloudFront distribution with the Application Load Balancer as the origin, it accelerates the delivery of the dynamic PHP webpage, reducing latency and improving user experience.

##### 1.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k2xylp0n9g76nayjgx4.png)

##### 2. Origin Domain Name: Select the Load balancer ***`my-LB`*** that you created

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4icc1c40dcmsr23wk3p.png)
- take defaults

##### 3.

***Note:*** enable the query string forwarding because our server can accept the query string parameter ID

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cjmz5iwibkkh041jtwtz.png)

***Note:*** The TTL option will be in disabled for dynamic contents by setting it to 0.

##### 4.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/018f2agjftq8hsoazbfs.png)

- Take all defaults

- Click on the Create distribution 

##### 5. Status column shows Deploying, and then shows Last Modified Date for your distribution. Wait for the deployment to complete.

***Note:*** Wait for This process will take around 4-5 minutes.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yka2y6dk0ynz6rdkuu8b.png)

## 6. Test the distribution.

##### 1. test the CloudFront distribution to verify that it is correctly serving content from the EC2 instances through the Application Load Balancer. 

- Copy the CloudFront distribution Domain name and paste it in the browser and hit [enter].

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0pb8k8nuqfc8axoomf2s.png)

##### 2. refresh the page and see the instance ID change, and the time will keep incrementing.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g592lfqtv8kf3ff797ho.png)

##### 3. Pass the query string parameter to CloudFront domain.

```
http://<domain name>/?id=CloudFront

http://dua7m5h1l3jyg.cloudfront.net/?id=CloudFront
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rf5eet5qbxf040hvg0lj.png)

# Cleanup

- Delete Security Group and EC2 instance
- Remove index.php file from S3 bucket
- Delete Target Group and Load Balancer
- Delete Cloudfront Distribution

# What we have done so far

- We have successfully created and tested the CloudFront Distribution with the Application Load Balancer as the origin. 
- It show how it accelerates the delivery of the dynamic PHP webpage, reducing latency and improving user experience.