Setup for CloudFront

You can improve resiliency and increase availability for specific scenarios by setting up CloudFront with origin failover. To get started, you create an origin group in which you designate a primary origin for CloudFront plus a second origin. CloudFront automatically switches to the second origin when the primary origin returns specific HTTP status code failure responses.

We are going to configure CloudFront with origin failover in the below steps using our active-primary-uibucket-xxx S3 static website as our primary origin and our passive-secondary-uibucket-xxxx S3 static website as our failover origin.

You will need the Amazon CloudFormation output parameter values from the Primary-Active and Passive-Secondary stacks to complete this section. For help, refer to the CloudFormation Outputs section of the workshop.

Create the Amazon CloudFront Distribution

1.1 Click CloudFront to navigate to the dashboard.

1.2 Click the Create a CloudFront Distribution button.

In Step 1.3, DO NOT choose the Amazon S3 active-primary-uibucket-xxxx bucket in the dropdown for the Origin Domain. The Cloudfront distribution will not work if you do this.

1.3 Enter the WebsiteURL value from the Active-Primary output values as the Origin Domain.

One of the purposes of using CloudFront is to reduce the number of requests that your origin server must respond to directly. With CloudFront caching, more objects are served from CloudFront edge locations, which are closer to your users. This reduces the load on your origin server and reduces latency. However, that behavior masks our mechanism (disabling the UI bucket) from properly simulating an outage. For more information, see Amazon CloudFront Optimizing caching and availability . In production, customers typically want to use the default value CachingOptimized.

The next section Failover to Secondary, will not work without completing Step 1.4.

1.4 In the Cache key and origin requests section, select CachingDisabled for the Cache Policy to disable CloudFront caching.

1.5 Click the Create Distribution button.

Configure an Additional Origin

We will now add an additional Origin and use our secondary-passive-uibucket-xxxx.

2.1 Click the Origins link, then click the Create origin button.

In Step 2.2, DO NOT choose the Amazon S3 passive-secondary-uibucket-xxxx bucket in the dropdown for the Origin Domain. The Cloudfront distribution will not work if you do this.

2.2 Enter the WebsiteURL value from the Passive-Secondary output values as the Origin Domain. Click the Create origin button.

Configure the Origin Group

3.1 Click the Create Origin Group link.

3.2 Select active-primary-uibucket-xxxx as the Origins, then click the Add button.

3.3 Select passive-secondary-uibucket-xxxx as the Origins, then click the Add button.

3.4 Enter hot-standby-origin-group as the Name. Enable all checkboxes for Failover criteria, then click the Create origin group.

Configure Behaviors

4.1 Click the Behaviors link. Select Default (*), then click the Edit button.

4.2 Select hot-standby-origin-group as the Origin and Origin Groups.

4.3 Click the Save changes button.

4.4 Click the Distributions link.

4.5 Wait for Status to be Enabled and for Last Modified to have a date.

Verify the Distribution

5.1 Copy the CloudFront Distribution’s Domain Name into a new browser window.

5.2 Confirm that the website’s header says The Unicorn Shop - us-east-1.

Congragulations! Your CloudFront distribution is working!