Skip to content

aws-samples/apigw-multi-region-failover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Amazon API Gateway Multi-Region Public REST API Failover

Companies often have multiple teams managing different services behind a shared public API. In disaster recovery scenarios, each team needs the ability to fail over their services independently.

This demo demonstrates an Amazon API Gateway multi-region active-passive public API that proxies two independent multi-region active-passive service APIs. The primary and secondary regions can be configured independently for the external API and each service. This allows you to fail over the external API and each service independently as needed for disaster recovery.

alt text

Learn more about this pattern at Serverless Land: https://serverlessland.com/repos/apigw-multi-region-failover

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the AWS Pricing page for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

Deployment Instructions

Before deploying this application you will need the following:

  • A public domain (mydomain.com) registered with Amazon Route 53. More details here
  • An AWS Certificate Manager (ACM) certificate (*.mydomain.com) for your domain name on both primary and secondary regions you plan to deploy your APIs on. More details here

Then follow the following steps, in this exact order:

  1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
    git clone https://github.com/aws-samples/apigw-multi-region-failover.git
    
  2. Deploy the Amazon Route 53 Application Recovery Controller (ARC) stack
  3. Deploy the service1 stack
  4. Deploy the service2 stack
  5. Deploy the external api stack

How it works

You will deploy 3 applications (external api, service2 and service 2) in two separate regions. The external api (i.e. https://externalapi.mydomain.com) is your entry point to access service 1 (i.e. https://externalapi.mydomain.com/service1) and service 2 (i.e. https://externalapi.mydomain.com/service2). The external api uses public HTTP endpoint integrations (/service1 and /service2) to access service 1 and service 2.

If an issue with the primary region occurs, you can user Amazon Route53 ARC to route traffic to the secondary region. You can failover each application (external api, service1 and service2) independently.

This example demonstrates the failover only and does not encompass authentication and data for the multiple regions.

Testing

Deploy all 3 applications to both primary and secondary regions. Traffic will initially be routed to the primary region only. Use Amazon Route 53 ARC to independently failover the applications to the primary or secondary region. Amazon Route 53 will then route traffic the the new chosen region for each service.

Edit the test.sh file on lines 3-5 to point to your api endpoint. Then give that file execution permissions and run it:

chmod +x ./test/sh
./test.sh

This script will send an HTTP request to each one of your 3 endpoints every 5 seconds. You can then use Amazon Route 53 ARC to failover your services independently and see the responses being served from different regions.

For example, on the test below, we initially had the external api and service 1 routing traffic to us-east-1. Service 2 was initially routing traffic to us-west-2.

alt text

  1. We failed over service2 from us-west-2 to us-east-1.
  2. We failed over service1 from us-east-1 to us-west-2.
  3. We failed over the external api from us-east-1 to us-west-2.

Notes: Each service (external app, service1 and servce 2) have their own Amazon Route 53 ARC control pannel. To manage routing controls for each service, you need to use their specific control panels. You can check the route53 stack outputs to see the details for each control panel.

Cleanup

Please follow the following steps, in this exact order.

  1. Delete service1 stacks
  2. Delete service2 stacks
  3. Delete the external stacks
  4. Delete the Route 53 ARC stack

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages