Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a Route 53 Record to an ALB? (AWS)

I want to create a new alb and a route53 record that points to it.

I see I have the DNS name: ${aws_lb.MYALB.dns_name}

Is it possible to create a cname to the public DNS name with aws_route53_record resource?

like image 687
red888 Avatar asked Feb 22 '18 03:02

red888


People also ask

How does Route 53 work with load balancer?

The AWS Domain Name System (DNS) service, Amazon Route 53, performs global server load balancing by responding to a DNS query from a client with the DNS record for the region that is closest to the client and hosts the domain.

How do I record AWS Route 53?

On the Hosted zones page, choose the name of the hosted zone that you want to create records in. Choose Create record. Choose and define the applicable routing policy and values.

How do you create a Route 53 alias record?

AWS A Record Alias via AWS Route 53 ConsoleClick on the Resource Record (the A Record) for the Domain/Sub-Domain you would like to edit. On the right hand corner of the screen, you get to edit the Record Set. Type for this record will remain as “A — IPv4 address”. But, in the Alias: section, choose “Yes”.


1 Answers

See the Terraform Route53 Record docs

You can add a basic CNAME entry with the following:

resource "aws_route53_record" "cname_route53_record" {
  zone_id = aws_route53_zone.primary.zone_id # Replace with your zone ID
  name    = "www.example.com" # Replace with your subdomain, Note: not valid with "apex" domains, e.g. example.com
  type    = "CNAME"
  ttl     = "60"
  records = [aws_lb.MYALB.dns_name]
}

Or if you're are using an "apex" domain (e.g. example.com) consider using an Alias (AWS Alias Docs):

resource "aws_route53_record" "alias_route53_record" {
  zone_id = aws_route53_zone.primary.zone_id # Replace with your zone ID
  name    = "example.com" # Replace with your name/domain/subdomain
  type    = "A"

  alias {
    name                   = aws_lb.MYALB.dns_name
    zone_id                = aws_lb.MYALB.zone_id
    evaluate_target_health = true
  }
}
like image 158
Adam Westbrook Avatar answered Sep 19 '22 07:09

Adam Westbrook