By using AWS re:Post, you agree to the Terms of Use

Configure DNS record in CloudFormation for Elastic Beanstalk Environment

0

Hi

I have a CloudFormation template where I try to create an A record as alias to my Elastic Beanstalk environment in the eu-west-1 region:

...
DNSRecord:
    Type: AWS::Route53::RecordSet
    Properties:
      HostedZoneId: !Ref ZoneID
      Comment: DNS name for elastic beanstalk.
      Name: !Ref AppUrl
      Type: A
      AliasTarget:
        EvaluateTargetHealth: false
        DNSName: !GetAtt AppEnvironment.EndpointURL
        HostedZoneId: Z2NYPWQ7DFZAZH
...

The hosted zone id of the AliasTarget is configured as provided in this post

However, this always gives an error in CloudFormation: Tried to create an alias that targets ...., type A in zone Z2NYPWQ7DFZAZH, but the alias target name does not lie within the target zone

I also created the record manually in the AWS Console. When I describe this record set with the CLI with this command: aws route53 list-resource-record-sets --hosted-zone-id ******* I see the same zoneId for the alias.

{
   "ResourceRecordSets": [
      ...
      {
            "Name": "**********",
            "Type": "A",
            "AliasTarget": {
                "HostedZoneId": "Z2NYPWQ7DFZAZH",
                "DNSName": "**********",
                "EvaluateTargetHealth": false
            }
        },
      ...
   ]
}

Did I make a mistake in the CloudFormation config?

2 Answers
0

Are you using an Elastic Load Balancer? If so specify the value of the hosted zone ID for the load balancer.

You can do this command to get the CanonicalHostedZoneNameID

aws elb describe-load-balancers --region eu-west-1

From https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-route53-aliastarget.html

ELB load balancer

Specify the value of the hosted zone ID for the load balancer. Use the following methods to get the hosted zone ID:

* Service Endpoints table in the "Elastic Load Balancing Endpoints and Quotas" topic in the Amazon Web Services General Reference: Use the value that corresponds with the region that you created your load balancer in. Note that there are separate columns for Application and Classic Load Balancers and for Network Load Balancers.

  • AWS Management Console: Go to the Amazon EC2 page, choose Load Balancers in the navigation pane, select the load balancer, and get the value of the Hosted zone field on the Description tab.

  • Elastic Load Balancing API: Use DescribeLoadBalancers to get the applicable value. For more information, see the applicable guide:

Classic Load Balancers: Use DescribeLoadBalancers to get the value of CanonicalHostedZoneNameID.

Application and Network Load Balancers: Use DescribeLoadBalancers to get the value of CanonicalHostedZoneID.

  • CloudFormation Fn::GetAtt intrinsic function: Use the Fn::GetAtt intrinsic function to get the applicable value:

Classic Load Balancers: Get CanonicalHostedZoneNameID.

Application and Network Load Balancers: Get CanonicalHostedZoneID.

  • AWS CLI: Use describe-load-balancers to get the applicable value. For more information, see the applicable guide:

Classic Load Balancers: Use describe-load-balancers to get the value of CanonicalHostedZoneNameID.

Application and Network Load Balancers: Use describe-load-balancers to get the value of CanonicalHostedZoneID.*

profile picture
answered 17 days ago
0

OK you mentioned its a single instance environment but i noticed in your CF template you are getting the DNS name like this:

DNSName: !GetAtt AppEnvironment.EndpointURL

However in single instance environments that will give you the IP address NOT the CNAME

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-beanstalk-environment.html#aws-properties-beanstalk-environment-return-values

Fn::GetAtt

The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.

EndpointURL

For load-balanced, autoscaling environments, the URL to the load balancer. For single-instance environments, the IP address of the instance.

Example load balancer URL:

awseb-myst-myen-132MQC4KRLAMD-1371280482.us-east-2.elb.amazonaws.com

Example instance IP address:

192.0.2.0

profile picture
answered 17 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions