How do I configure my website to fail over to an S3 bucket when a Route 53 health check fails?

Last updated: 2022-09-06

I want to set up a static endpoint that my dynamic website can fail over to in the event there’s an issue with my infrastructure. How do I do that?

Short description

Before you get started, make sure that you have the following configured:

  • An active Amazon Route 53 hosted zone.
  • The dynamic version of your website is hosted on an Amazon Elastic Compute Cloud (Amazon EC2) instance.
  • The Route 53 hosted zone is already successfully routing your website traffic to your Amazon EC2 instance.

Resolution

Configure the hosted zone to fail over to a static website hosted in an Amazon Simple Storage Service (Amazon S3) bucket for unhealthy Route 53 checks. The static website is what users see when the hosted zone fails over. After your health check returns to healthy, the hosted zone automatically routes traffic to your primary endpoint. Follow the instructions for hosting a static website on Amazon S3.

Note:

Create the Route 53 health check

  1. Open the Amazon Route 53 console, and then choose Health checks.
  2. Choose Create health check, and enter the following:
    For Name, enter a name for the health check.
    For What to monitor, choose Endpoint.
    For Specify endpoint by, choose IP address.
    For Protocol, choose HTTP.
    For IP address and Host name, enter the IP and host name for your EC2 instance.
    For Port, choose 80.
    Leave Path empty, or specify the page that you want to check.
  3. Choose Next.
  4. For Create alarm, choose Yes.
  5. Choose Create health check.

Note: For more information, see Creating and updating health checks.

Create a record set for your primary endpoint

  1. Open the Amazon Route 53 console, and then choose Hosted zones.
  2. For Domain Name choose the domain of the hosted zone that you want to create the record for.
  3. Choose Create record, and then create a record set with these values (for all other fields, use values that fit your use case):
    For Record Name, enter the name. Make sure that it's the same as the S3 bucket name.
    For Record type, choose A – Routes traffic to an IPV4 address and some AWS resources.
    For Alias, leave it as Off.
    For Routing Policy, choose Failover.
    For Failover Record Type, choose Primary.
    For Associate with Health Check, choose Yes, and then choose the health check you created previously.
  4. Choose Create records.

Create the failover endpoint

  1. Open the Amazon Route 53 console, and then choose Hosted zones.
  2. Choose the hosted zone that you want to create the record for.
  3. Choose Create record, and input the following:
    For Record name, use the same value that you entered for the primary record.
    For Record type, choose A – Routes traffic to an IPV4 address and some AWS resources.
    For Alias, choose Yes.
    Note: Aliases automatically use a time to live (TTL) that matches the alias target.
    For Alias Target, choose the S3 bucket that you created previously.
    For Routing Policy, choose Failover.
    For Failover Record Type, choose Secondary.
    For Set ID, enter a name.
    Note: The name for the Set ID on your failover endpoint must be different from the name of the Set ID on your primary endpoint.
    For Associate with Health Check, choose No.
  4. Choose Create records.