Block traffic to your website from Russia and Belarus using CloudFront
Tags: tutorial, devops, aws, ukraine
Published: 2022-03-01 10:50:37

---
title: Block traffic to your website from Russia and Belarus using CloudFront
published: true
description: I want to invite you all to block your website traffic from Russia and Belarus to show support for the Ukrainian people. Let me show you how to do just that.
tags: #tutorial, #devops, #aws, #ukraine
cover_image: https://crocoder.dev/static/b0b983a13df7ada597d971208dbf9c55/39fa8/block-russia-using-cloudfront.webp
---


Russia invaded Ukraine on the 24th of February 2022. Belarus offers logistic support to the Russian army. 

Our company website **won't be available in Russia and Belarus** until the invasion stops. We don't intend to punish our readers from Russia and Belarus but to show dissatisfaction and disapproval of the political and philosophical stance of the Russian government.

Our company and I are **strong supporters and believers** in **individual liberty, free trade, and free association**. In addition to being against war, we strongly oppose evil and destructive ideas that support autocracies. Make no mistake, **this is not the doing of one man**, but a joint effort of individuals who believe it is not you who should be deciding how to live your life.

We will continue doing as much as possible to show our support for the Ukrainian people and invite you all to do the same. If you use CloudFront as your CDN, the following tutorial will help you to **enable CloudFront Geographic Restrictions** and block traffic from Russia and Belarus. 

If you are using any other CDN or a different provider, send us an email at [hello@crocoder.dev](mailto:hello@crocoder.dev). I will personally assist you in blocking traffic.

<hr>

I will show you three ways to block traffic depending on how your CloudFront distribution is provisioned.

- Manually / AWS Console
- CloudFormation
- Terraform

<hr>

## Manually / AWS Console

Open [CloudFront Distributions](https://console.aws.amazon.com/cloudfront/v3/home) and choose the distribution. 

![CloudFront distribution screen](https://crocoder.dev/static/884bdf84c97e15bb79656f4a41cfc404/3b477/step1.png)
<br>

Click on the `Geographic restrictions` tab. Click on edit button.

![CloudFront Geographic restriction tab](https://crocoder.dev/static/55e2e6ef28f951518c16f6d8332fd6cf/3b477/step2.png)
<br>

 Check `Restriction type` - `Block list` and select from the dropdown Russia and Belarus. Click Save changes.

![Edit geographic restrictions dropdown](https://crocoder.dev/static/37a224ef2a3aec1ec8191ed9677cdc0c/c1b63/step3.png)
<br>

You have just blocked all traffic from Russia and Belarus. All visitors from those locations will get 403 (Forrbidden) status code.

![CloudFront Geographic restriction tab with blocked traffic from Russia and Belarus](https://crocoder.dev/static/514cb2fc49c8ded9f5c68dacc629ef9c/3b477/step4.png)
<br>


## CloudFormation

If you are deploying the CloudFront via CloudFormation add this code to `Restrictions` in `CloudFrontDistribution` `Properties`. 

Use the following code snippet:

```bash
CloudFrontDistribution:
  Type: 'AWS::CloudFront::Distribution'
  Properties:
    DistributionConfig:
      ...
      Restrictions:
        GeoRestriction:
          Locations:
          - RU
          - BY
          RestrictionType: blacklist
```  
<br>  



## Terraform

You can easily add restrictions object to your `aws_cloudfront_distributions`. 

Use the following code snippet:

```bash
resource "aws_cloudfront_distribution" "website_distribution" {
  ...
  restrictions {
    geo_restriction {
      restriction_type = "blacklist"
      locations        = ["RU", "BY"]
    }
  }
}
```

Thank you for reading. 🇺🇦