Amazon CloudFront with continuous integration and delivery pipeline
Tags: aws, cloudfront, cdn, cicd
Published: 2022-11-25 14:54:39

[Amazon CloudFront](https://medium.com/r/?url=https%3A%2F%2Faws.amazon.com%2Fcloudfront%2F) is one of AWS Networking and Content Delivery (N&CD) products which delivers content to the edge locations with _low latency_ and _high speed_. End users, in other words, visitors all around the globe can reach the content fast and securely. So it is a high end Content Delivery Network (CDN) with more than 410 Points of Presence (PoP) located globally by AWS. 

This blog post aims to explain how **continuous integration and continuous delivery (CI/CD)** works on CloudFront. For more information about creating CF distributions and integration with S3, please see [this guide](https://medium.com/r/?url=https%3A%2F%2Fdocs.aws.amazon.com%2FAmazonCloudFront%2Flatest%2FDeveloperGuide%2FGettingStarted.html). 

Below architecture shows a simple flow from end users to S3 origin bucket by using a CloudFront distribution. 

![Simple working concept of CloudFront and S3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v6juyhoxecoq8ka9e54u.png)
_Simple working concept of CloudFront and S3._

### So what is a CI/CD pipeline? 

It is an **agile** delivery workflow focusing on frequent and reliable development. It stands for Continuous Integration and Continuous Delivery. And the pipeline is the whole process from building to deployment. All process consist of four stages: **Build**, **Test**, **Deliver** and **Deploy**. 

CI/CD pipeline is important for technical teams and companies to reduce time-consuming jobs, such as iterative manual tasks or unpredictable human caused errors. 

### Then, what is the challenge of CI/CD for CDN? 

CDN changes are relatively slow. Because there is some configuration for content caching mechanism which understands the change of the origin content and distributes this change to all edge locations. And it takes some time to effect. Of course this configuration can be set properly to reduce the caching period, but this is not the only challenge. Besides that, a little misconfiguration can cause an outage to the end users. Therefore any kind of change action should be taken more carefully to prevent a possible outage. If the edge users cannot enter the front door, it is more likely to experience a global or regional service cut. 

### What is the solution then? 

AWS recently published a blog post to announce a new way to safely validate CDN changes. It is not a brand new concept in the server world, but it will be used widely soon for sure. 

The solution include a different type of distributions associated with the production distribution. It's called **staging distribution**. Now developers can safely test and validate all changes on staging part without concerning any sort of problematic issue. 

![Staging distribution in action.](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yftzmysil0ozal1j15pw.png)
_Staging distribution in action._

Traffic can be shifted to the staging by using two main continuous deployment policies. 

- Weight-based 

User has the control to specify the percentage of the user requests which will be routed to staging distribution. Change testing can start small but then increase easily. The change can be applied widely. 

- Header-based 

Only user requests with a specific HTTP header will be routed to staging distribution. This configuration is more useful when some local tests are needs to be done in a small-scaled testing environment. 

Since all already understood that the solution includes a way with two methods to develop software without any kind of interruption. So the main difference here is to safely test, integrate and validate a new load to the origin distribution. 

### Last words 

CI/CD usage and latest update on CloudFront have been explained briefly in this post. You can learn to create a staging distribution with the help of [this step by step guide](https://medium.com/r/?url=https%3A%2F%2Faws.amazon.com%2Fblogs%2Fnetworking-and-content-delivery%2Fuse-cloudfront-continuous-deployment-to-safely-validate-cdn-changes%2F) written on the same official blog post. Thank you for reading.