DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Automatic Failover and Failback for Legacy Multi-Port Application on AWS Cloud

Automatic Failover and Failback for Legacy Multi-Port Application on AWS Cloud

Customers want to have active-failover for their monolithic applications running on multiple ports which do not support load balancers.

Rahul Nagpure user avatar by
Rahul Nagpure
·
Jan. 16, 23 · Tutorial
Like (1)
Save
Tweet
Share
1.73K Views

Join the DZone community and get the full member experience.

Join For Free

Customers migrate their legacy applications to the cloud and want to use cloud-native services to improve their application availability. Customers want to have active-failover for their monolithic applications running on multiple ports which do not support load balancers.

This article shows a way to build a low-cost active-failover for monolithic, multi-port internal applications using Route53 and CloudWatch. This is only for an application running on multiple ports that wants to failover if any one of the ports goes down.

Prerequisites

  1. An AWS account with console access with full permissions on Route53 and CloudWatch and EC2.
  2. Route53 private hosted zone and health check
  3. CloudWatch metrics
  4. Linux EC2 instances

Understanding Overall Design

  • Internal users connect to the legacy application running on AWS cloud.
  • The application has been configured in a way to send all traffic to only primary server. 
  • One small lightweight shell script monitors all running ports inside the primary server and updates CloudWatch metrics. 
  • If any one of the ports goes down, a CloudWatch alarm will be triggered and Route53 will re-route all traffic to a secondary server within the next five minutes.
  • Once the primary server start working again, Route53 will route all traffic back to the primary server.

Server and Simple Shell Script

Create IAM Role to Update the CloudWatch Metrics

  1. The primary server must have permission to update CloudWatch to generate the metrics. 
  2. You may need at least following permissions.
  3. Assign this role to your servers.
 
{

    "Version": "2012-10-17",

    "Statement": [

        {

            "Sid": "VisualEditor0",

            "Effect": "Allow",

            "Action": "cloudwatch:PutMetricData",

            "Resource": "*"

        }

    ]

}

Put the following shell script in root user crontab in the server.

Change the instance ID and ports according to your configuration in the script.

 
#!/bin/bash

for port in "22" "25" "8080" "80"

do

lsof -i:"$port"  -P | grep IPv4  | grep LISTEN > /dev/null

if [ $? -eq 1 ]; then

   echo "$port is not listening"

   exit

fi

done

aws cloudwatch put-metric-data --metric-name Drives-health --dimensions Instance=i-066111111111100a66 --namespace "Custom" --value 1 --profile <default>

CloudWatch Alarm Configuration

  1. The shell script will send a health check in form of binary value "1" to CloudWatch.  
  2. CloudWatch will generate metrics based on health-check data.  
  3. Configure a CloudWatch alarm with the following conditions and send a notification to your desired SNS topic.

Route53 and Health Checks

Route53 Health Checks

  1. Create Route53 health check. 
  2. Select "state of monitoring alarm."
  3. Select CloudWatch alarm created in previous step.
  4. Route53 will monitor CloudWatch alarm with this health-check service. 

Route53 DNS Records

  1. Create a record for your application with failover routing policy. 
  2. While creating primary failover record type, make sure to select the health check ID created in the previous step.
  3. Do not select any health check ID while creating failover record type.

Testing

  1. Access a record URL from your browser and check the server receiving the incoming requests.
  2. Stop any one of the port on primary server, wait for a minimum of five minutes and access the URL again. 
  3. All requests should route to secondary server. 
  4. You can failback to the primary server by starting the stopped port. 

Summary

This pattern is for legacy monolithic applications that do not support a load balancer and running on multiple ports. I have given a very simple method to set up an application which can easily failover within five minutes without any AWS load balancer. 

AWS Load balancing (computing) Legacy system Cloud Continuous availability

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Web Application Architecture: The Latest Guide
  • Top 5 PHP REST API Frameworks
  • Artificial Intelligence in Drug Discovery
  • Three SQL Keywords in QuestDB for Finding Missing Data

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: