Enabling resiliency for a static website hosted on AWS Cloud
Tags: aws, s3, devops, failover
Published: 2021-03-02 15:21:56

"Everything fails all the time." says Werner Vogels, CTO & VP, Amazon.
Though, happily hosted [my personal website](https://bhuvana.pro) on [Amazon S3 as a static website hosting] (https://dev.to/aws-heroes/self-hosting-secured-static-web-site-using-s3-route-53-acm-cloudfront-411a) in the Mumbai region and set up [CI / CD to integrate the changes from GitHub repo to Amazon S3] (https://dev.to/aws-heroes/automated-deployment-to-static-website-5245). 
Is the disaster recovery in-place or is it resilient?


**What is Resiliency?**

Resiliency is the ability for a system to recover from a failure induced by load, attacks, and failures.

Amazon S3 is highly available and resilient for zonal failure but is the website resilient for a regional disaster like power, weather.,? Though the chances are very remote with AWS Cloud, let's make the website resilient by setting up disaster recovery. Of course, the cloud has better ways to help provide business continuity, and here is one.

### Table of Contents
* [AWS Services Used](#awsservices)
* [Best Practise](#bestpractise)
* [Design](#design)
* [Detailed Implementation Instructions](#detail)
  * [Create S3 bucket for Disaster Recovery](#s3forDR)
  * [Setup replication from example.com to dr.example.com](#replication)
  * [Create Origin Group](#createOriginGroup)

### AWS Services Used <a name="awsservices"></a>
* S3
* Route 53
* CloudFront
* IAM


### Best Practise <a name="bestpractise"></a>
* Ensure to tag all the resources that you create.
  * S3 dr bucket
* I have created two tags (Name: Bhuvana.pro and Usage: website), which will help for resource grouping and cost analysis.
* To standardize example.com, www.example.com, and dr.example.com is used as root and subdomain throughout this article


### Design <a name="Design"></a>
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/81sl9v22tf3b623r9u3x.png)

### Detailed Implementation Instructions <a name="detail"></a>
#### Create S3 bucket for Disaster Recovery <a name="s3forDR"></a>
* Create an S3 bucket (say dr.example.com) in a different region to set up a disaster recovery site for the website example.com and configure for static website hosting as follows

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/pl7357ag597thco8a3a5.png)

> **Important Note** Ensure versioning is enabled for both source (example.com) and destination bucket (dr.example.com)

#### Setup replication from example.com to dr.example.com <a name="replication"></a>

Select the main S3 bucket, example.com, and go to the **Management** tab, select **Replication rules** and click **Create replication rule**

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/n2edh7de5n898c9ei3vx.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/wzv702xue97lntrxj7qf.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/ms2mii9qldxc2zegfsid.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sovgx2legkow96q7z3if.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cy5hmq5b1n95mca43wn9.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7pr3vs8erd3nvgqa61tw.png)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/twux9ijzkwx2zl5kbp5o.png)


### Create Origin Group <a name="CreateOriginGroup"></a>
Our ultimate goal is to remove the single point of failure, implementing automatic detection of failure, and configure a redundant path to establish business continuity.

Now that you have the dr-s3 bucket created and replication configured source, let's proceed to add Origin Group to your Cloudfront distribution pointing to your static website.

Edit the Web distribution created for your static website and add another origin pointing to the disaster recovery S3 bucket (dr.example.com) and here is the setting for the new origin.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qyjt3kdyljmtj5tofza4.png)

The next step is to create an Origin Group with both the origins as follows with S3-example.com as primary and S3-dr.example.com as secondary.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59i6tlgeihordb1giwa9.png)

**Time to test for resiliency!!**
Go and delete the S3 bucket (example.com) where your static website is hosted and watch the Cloudfront re-directing the request to the disaster recovery S3 bucket (dr.example.com).