Skip to content

Deploying CloudFront Distribution with S3 Failover using Terraform

Notifications You must be signed in to change notification settings

chinmayto/terraform-aws-cloudfront-s3-failover

Repository files navigation

Deploying a cloudfront distribution with Multiple Origin for S3 Static Website using terraform

Deploying a cloudfront distribution with Multiple Origin for S3 Static Website using terraform

You can set up CloudFront with origin failover for scenarios that require high availability. We can create an origin group with two origins: a primary and a failover. If the primary origin is unavailable, or returns specific HTTP response status codes that indicate a failure, CloudFront automatically switches to the failover origin.

CloudFront routes all incoming requests to the primary origin, even when a previous request failed over to the secondary origin. CloudFront only sends requests to the secondary origin after a request to the primary origin fails.

Architecture Diagram:

alt text

alt text

Step 1: Create a primary and failover S3 Buckets with unique name and host static website by uploading files

Step 2: Create a cloudfront distribution with primary and failover origin

Step 3: Update S3 Bucket policy to allow access from cloudfront

Terraform Apply Output:

Apply complete! Resources: 9 added, 0 changed, 0 destroyed.

Outputs:

cloudfront_domain_name = "http://d1rwkmekbjnbkd.cloudfront.net"

S3 Buckets

alt text

CloudFront Distribution:

alt text

CloudFront Distribution Origin as S3 primary and failover and origin group

alt text

alt text

S3 Bucket Policy to allow access from cloudfront - primary and failover bucket

alt text

alt text

Using cloudfront domain name to access S3 static website

alt text

Failover to S3 failover bucket by removing s3 primary bucket policy manually from console (after TTL timeout)

alt text

Terraform Destroy Output:

Destroy complete! Resources: 9 destroyed.

Resources:

AWS CloudFront: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/Introduction.html

AWS CloudFront Origin Failover: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/high_availability_origin_failover.html

About

Deploying CloudFront Distribution with S3 Failover using Terraform

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published