Securing your Load Balancer with CloudFront
Tags: tutorial, security, cloud, webdev
Published: 2022-03-24 23:24:47

## DAY 24 - Securing your Load Balancer with CloudFront - Day Twenty Four

[![Image tweet](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jfjzxg64r7q0i8ra6b8t.png)![Image Cover](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1i0zktyhk5weht4n59wp.png)](https://twitter.com/intent/tweet?text=Securing%20your%20Load%20Balancer%20with%20CloudFront%2C%20a%20blog%20by%20%40anuvindhs%0A%23security%20%23cloud%20%23aws%20%23loadbalancer%20%23cdn%20%23CloudFront%0A%0Ahttps%3A%2F%2Fdev.to%2Faws-builders%2Fsecuring-your-load-balancer-with-cloudfront-20a1%20)


[100 days of Cloud on GitHub](https://github.com/anuvindhs/100daysofcloud) - [Read On iCTPro.co.nz](https://ictpro.co.nz) - [Read on Dev.to](https://dev.to/anuvindhs)



------


Restrict your LoadBalancer's public access, let internet have access to your app only via CloudFont.

## Prerequisite
- Understanding of how LoadBalancer work.
- Your app delivering content via CDN from LoadBalancer.
- Application Load Balancer with at least one listener.
![Image LB](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ihmui1hwhdlmideil3i.png)
 
## Tutorial

### Updating Rules 

As of now I believe you have at least configured Listeners for your Load Balancer.

lets update the rules for the listener

- goto **LoadBalaner** from **EC2 dashboard** and select your LB.
- Then Select listeners and Click **View/edit rules**

 ![Image rule](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/le4njyo631bns61owunc.png)
 
- Select edit ![Image edit](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eea30cqvop9mvy27ouyl.png)

-  Delete the current **forward to** , and click **add action**then **Return fixed response...**.
-  Response code = **403** , Content-Type = **text/plain** , Response body = **Access Denied** , Now click the tick mark and update.
 ![Image rule1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u2wzxc91bcj20qoy1ozw.png)
 
#### Custom header rule

 In this stage we create a Custom header.

- Goto **+** and click **Insert Rule**.
-  Add condition as **Http header**.
- add **X-Custom-Header** as header Header name, give a random unique value **RandomValue-1234567890**.
- Now foward this to your **TargetGroup**
- Now Save it.
 ![Image rule2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wft085v7dl9ih244vg50.png)
 

### Update the CloudFront -CDN

- Goto CloudFront console and select your distribution.
- Select **Orgins** and click **edit**.

- Under **Add custom header - optional** 
 
- Update Header name =**X-Custom-Header** , Value=**RandomValue-1234567890** and click **Save**
![Image CDN](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3k7ivuiqyis569ngovjz.png)

 🎉**Congratulations**🎉 you have successfully secured your load balancer.


![Image Congratulations](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7pr71ab9x74dqisiygt0.gif)

  ----------

**✅Connect with me on [Twitter](https://twitter.com/intent/follow?ref_src=anuvindhs&screen_name=anuvindhs)
 🤝🏽Connect with me on [Linkedin](https://www.linkedin.com/in/anuvindhs)
🧑🏼‍🤝‍🧑🏻 Read more post on [dev.to](https://dev.to/anuvindhs) or  [iCTPro.co.nz](https://ictpro.co.nz)
💻 Connect with me on [GitHub](https://github.com/anuvindhs)**


{% user anuvindhs %}