Search code examples
amazon-web-servicesaws-cliamazon-route53

AWS CLI - route53 change-resource-record-sets command failing if A record but passes if CNAME


I am trying to add DNS records on existing hosted zone. I was trying the below command with ResourceRecordSet type as A record and also CNAME record. The command which is trying to create A record fails but the same command when changed to CNAME works

Failing Command

aws route53 change-resource-record-sets --hosted-zone-id XXXXXXXXXXXXX --change-batch {"Changes": [{"Action": "CREATE","ResourceRecordSet": {"Name": "api-test-1.envio.systems","Type": "A","TTL": 30,"ResourceRecords": [{"Value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-14xxxxxxxxxxxxx26.elb.eu-central-1.amazonaws.com"}]}}]}

Error:

An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation: [Invalid Resource Record: FATAL problem: ARRDATAIllegalIPv4Address (Value is not a valid IPv4 address) encountered with 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-14xxxxxxxxxxxxx26.elb.eu-central-1.amazonaws.com.']

Below command works and only thing that is changed is ResourceRecordSet Type from A to CNAME

aws route53 change-resource-record-sets --hosted-zone-id XXXXXXXXXXXXX --change-batch {"Changes": [{"Action": "CREATE","ResourceRecordSet": {"Name": "api-test-st-1.envio.systems","Type": "CNAME","TTL": 30,"ResourceRecords": [{"Value": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-14xxxxxxxxxxxxx26.elb.eu-central-1.amazonaws.com"}]}}]}

What is the problem and why CNAME works with the same command but not A record?


Solution

  • In DNS, an A ("address") record points to an IPv4 address. A CNAME record points to another dns name.

    AWS Does have a concept of record aliases which is essentially a CNAME record that does an internal Route 53 lookup of the value and comes out as an A record.

    https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-elb-load-balancer.html describes how to set up an Alias record. https://aws.amazon.com/premiumsupport/knowledge-center/alias-resource-record-set-route53-cli/ talks about doing it with the CLI, which more accurately represents the fields the API accepts. Basically, you specify the Hosted Zone ID of the ELB's DNS record along with its address.

    https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/resource-record-sets-choosing-alias-non-alias.html