Search code examples
amazon-web-servicesamazon-route53

Is it possible to create 2 A records alias and ip in AWS Route53 for the same record name?


I have the following use case: I have a system in which I serve both the web and api via one ec2 instance with public ip. I have a single Route53 A type record pointing to the EIP of the ec2 instance.

As the application grows I want to move to a more scalable architecture that uses AWS ALB. I have created the alb and configured everything so it points to the new ec2 instances one for api one for web etc.

The thing is, I want to do this with 0 downtime and want to keep both A records in round-robin for 2-3 days then remove the A record of the EC2.

I tried this both with terragrunt and also manually in the Route53 UI and do get: (InvalidChangeBatch 400: Tried to create resource record set [name='web.secret.', type='A'] but it already exists)

My goal is to have one A record of type alias pointing to the loadbalancer dns and one A record pointing to the ip of the existing ec2 This way requests round-robin and some users use the alb some the ec2 which both are up then I remove the ec2 ip record and leave all traffic go to the alb.


Solution

  • Yes, this is possible via Weighted routing policy.

    Simply create 2 records with Weighted as a Routing policy and assign them unique Record IDs while keeping the subdomain same.

    To distribute traffic, assign weights based on your need. Let say you want to send 70% of the traffic to ALB and 30% to the EC2. Then add a weight of 70 in ALBs records and 30 in EC2s record.