How to write latency based Route 53 alias recordset resource in AWS CloudFormation

Viewed 644

According to this AWS document this AWS document, I can create latency based resource record aliased to an application load balancer, but I do not see an option for Routing Policy in the syntax where I can define latency.

Here are my example recordsets in Route 53 console from, two different regions for the same application. Since it is an aliased record, my understanding is that I do not need use a Health Check configuration. I can just enable Evaluate target health instead.

For us-east-1:

  • Record name: mywebsite.example.com
  • Record type: A
  • Alias: Yes
  • Route traffic to: Alias to Application and Classic Load Balancer
    US East (East Virginia) [us-east-1]
    dualstack.internal-mywebsite-alb-1234567890.us-east-1.elb.amazonaws.com.
  • Routing policy: Latency
  • Region: US East (East Virginia)
  • Health check: optional (None)
  • Evaluate target health: Yes
  • Record ID: us-east-1-mywebsite-alb

For us-west-2:

  • Record name: mywebsite.example.com
  • Record type: A
  • Alias: Yes
  • Route traffic to: Alias to Application and Classic Load Balancer
    US West (Oregon) [us-west-2]
    dualstack.internal-mywebsite-alb-1234567890.us-west-2.elb.amazonaws.com.
  • Routing policy: Latency
  • Region: US West (Oregon)
  • Health check: optional (None)
  • Evaluate target health: Yes
  • Record ID: us-west-2-mywebsite-alb

How can I transform them into CloudFormation resource(s)? A complete snippet for the resource would be very helful.

Update:

I have tried the following but did not work:

Resources:
  TestDevALB:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Type: application
      Scheme: internal
      # LoadBalancerAttributes:
      Subnets:
        - subnet-1111abcd2222abcde
        - subnet-2222abcd3333abcde
      SecurityGroups:
        - sg-1111abcd2222abcde

AlbDnsRecordSet:
  Type: AWS::Route53::RecordSet
  Properties:
    HostedZoneId: ABCD1234EFGH5678IJKL
    Name: testdev.example.com
    Type: A
    AliasTarget:
      HostedZoneId: !GetAtt 'TestDevALB.CanonicalHostedZoneID'
      DNSName: !GetAtt 'TestDevALB.DNSName'
    Region: us-west-2

I get error: An error occurred (ValidationError) when calling the CreateStack operation: Invalid template property or properties [AlbDnsRecordSet]

Update-2: The above error was due to indent. I added the target health check as well. The following worked. Thanks @marcin.

Resources:
  TestDevALB:
    Type: AWS::ElasticLoadBalancingV2::LoadBalancer
    Properties:
      Type: application
      Scheme: internal
      # LoadBalancerAttributes:
      Subnets:
        - subnet-1111abcd2222abcde
        - subnet-2222abcd3333abcde
      SecurityGroups:
        - sg-1111abcd2222abcde

  AlbDnsRecordSet:
    Type: AWS::Route53::RecordSet
    Properties:
      HostedZoneId: ABCD1234EFGH5678IJKL
      Name: testdev.example.com
      Type: A
      AliasTarget:
        HostedZoneId: !GetAtt 'TestDevALB.CanonicalHostedZoneID'
        DNSName: !GetAtt 'TestDevALB.DNSName'
        EvaluateTargetHealth: true
      Region: us-west-2
      SetIdentifier: TestDev-uswest2
0 Answers
Related