Saturday, December 27, 2025

AWS ARECORD VS CNAME

Absolutely! Let’s create a complete, structured blog-style explanation that ties together DNS, Route 53, A vs CNAME records, AWS vs Kubernetes, LocalStack, Spring Boot, and failover, in a clear, step-by-step narrative. I’ll make it educational, blog-ready, and thorough.


🌐 Understanding DNS, Route 53, and Failover: From AWS API Gateway to Kubernetes Spring Boot

In modern cloud architecture, DNS and failover are crucial for building highly available services. This post explains everything from the basics of DNS records to how AWS Route 53 works with both managed API Gateways and your own Kubernetes-based Spring Boot services.

We’ll cover:

  1. What DNS is

  2. A records vs CNAME

  3. AWS API Gateway and why it provides a DNS name

  4. Route 53 failover

  5. LocalStack simulation

  6. Kubernetes + Spring Boot failover setup

  7. Differences and best practices


1️⃣ What Is DNS?

DNS (Domain Name System) translates human-readable domain names into machine-readable IP addresses.

Example:

api.example.com → 93.184.216.34

Without DNS, we’d have to remember IP addresses for every server.

Key Records

Record TypeMaps ToExample
A (Address)IPv4 Addressapi.example.com → 192.168.1.100
CNAME (Canonical Name)Another DNS nameapi.example.com → my-gateway.example.com

2️⃣ Understanding A Records

An A record maps a domain name directly to an IP address.

api.hello.com  →  192.168.49.2

When to use A record:

  • You control the IP

  • Service is reachable via IP (e.g., Kubernetes NodePort, LoadBalancer)

  • Health checks and failover operate directly on IP

Example in Kubernetes

If you run a Spring Boot service in Kubernetes:

NodePort: 192.168.49.2:30001 → app-a
NodePort: 192.168.49.2:30002 → app-b

You can create an A record in Route 53:

api.hello-localstack.com → A → 192.168.49.2

DNS resolves directly to the node IP, and Route 53 health checks can monitor it.


3️⃣ Understanding CNAME Records

A CNAME record maps a domain name to another domain name, not directly to an IP.

api.example.com → CNAME → abc123.execute-api.us-east-1.amazonaws.com

Resolution flow:

  1. Client queries api.example.com

  2. DNS returns abc123.execute-api.us-east-1.amazonaws.com

  3. DNS resolves that hostname to an IP

  4. Client connects to the resolved IP

When to use CNAME:

  • The target is a managed service with no fixed IP (e.g., AWS API Gateway)

  • You want a friendly custom domain pointing to an existing service

  • You need automatic IP updates handled by the service provider


4️⃣ AWS API Gateway and DNS Names

When you create an API Gateway in AWS:

  • AWS manages the servers

  • You do not get a fixed IP

  • AWS provides a DNS name like:

abc123.execute-api.us-east-1.amazonaws.com

This is why, in the LocalStack Python tutorial:

12345.hello-localstack.com → CNAME → 12345.execute-api.localhost.localstack.cloud

You cannot use an A record here because there is no stable IP — only a managed hostname.


Key Difference: AWS vs Your Own Gateway

FeatureAWS / LocalStackSpring Boot / K8s
IPManaged, dynamicKnown (Node/LB IP)
DNSProvidedOptional
ScalingAWS handlesYou handle pods & replicas
FailoverAWS internalYou configure health checks

5️⃣ Route 53 Failover

Route 53 is AWS’s DNS service. It allows:

  • Mapping domain names → IPs or other DNS names

  • Health-check–based failover

  • Weighted routing or latency-based routing

Failover Example

api.hello-localstack.com
  ├── PRIMARY → 192.168.49.2 (app-a) Health: OK
  └── SECONDARY → 192.168.49.2 (app-b) Health: OK

If app-a fails, Route 53 automatically returns the secondary IP.


6️⃣ LocalStack: Simulate AWS Locally

LocalStack allows you to run AWS services locally, including:

  • Route 53

  • API Gateway

  • Lambda

It’s perfect for testing failover without touching AWS.

Example Command

awslocal route53 change-resource-record-sets \
--hosted-zone $HOSTED_ZONE_ID \
--change-batch '{
  "Changes": [
    {
      "Action": "CREATE",
      "ResourceRecordSet": {
        "Name": "12345.hello-localstack.com",
        "Type": "CNAME",
        "TTL": 60,
        "ResourceRecords": [
          {"Value": "12345.execute-api.localhost.localstack.cloud"}
        ]
      }
    }
  ]
}'

This creates a CNAME pointing to LocalStack’s API Gateway.


7️⃣ Kubernetes + Spring Boot Failover Setup

Instead of using API Gateway:

  1. Deploy multiple Spring Boot services in Kubernetes (app-a, app-b)

  2. Expose them using NodePort or LoadBalancer

  3. Use Route 53 A records pointing to node or load balancer IPs

  4. Add health checks to enable failover

Example

NodePort: 192.168.49.2:30001 → app-a
NodePort: 192.168.49.2:30002 → app-b

DNS in Route 53:

api.hello-localstack.com → A → 192.168.49.2

Route 53 evaluates health and returns the healthy backend’s IP.


8️⃣ Why Not CNAME in K8s?

  • Pods/services have direct IPs

  • Using A records is simpler and faster

  • CNAME is only needed if your service already has a hostname


9️⃣ Choosing Between A Record and CNAME

ScenarioRecommended RecordReason
API Gateway (AWS/LocalStack)CNAMEManaged DNS name, no fixed IP
Kubernetes NodePort / LoadBalancerAIP known, health checks operate on IP
CloudFront / ALBAliasAWS-managed DNS pointing to AWS resource
Your own host with hostnameCNAMEAlias to another DNS name

🔑 Summary

  1. DNS translates domain names to IPs or other domain names.

  2. A records → IP, CNAME → DNS name.

  3. AWS API Gateway gives a DNS name → use CNAME.

  4. Your Spring Boot/K8s API Gateway exposes IP → use A record.

  5. Route 53 failover switches traffic based on health checks.

  6. LocalStack lets you simulate all this locally.

Mental rule: “If the service provides an IP → use A record; if it provides a hostname → use CNAME.”


This is everything from the basics to a full Route 53 failover setup — from Python AWS API Gateway to Java Spring Boot in Kubernetes.


If you want, I can create a diagram-rich version of this blog with:

  • AWS API Gateway vs K8s Spring Boot flow

  • DNS resolution with A vs CNAME

  • Route 53 failover logic

This makes it visually compelling for readers.

Do you want me to do that next?

No comments:

Post a Comment

LocalStack AWS emulator

  Login to local stack using Google Id kr11.neeraj@gmail.com https://app.localstack.cloud/getting-started Note down the  Personal Auth Token...