Registering, changing, and deleting records to Route 53 using AWS CLI
Note:
I verified the use of the parameter “–dns-name” in the command [aws route53 list-hosted-zones-by-name], The returned result did not meet the request. Example:
aws route53 list-hosted-zones-by-name --dns-name example.com { "HostedZones": [ { "Id": "/hostedzone/Z01404082JK1xxxxx", "Name": "dev.luvina.lixx.", "CallerReference": "19fc7ef0-58bb-4c14-b086-cd3c7fbbb838", "Config": { "Comment": "dev.luvina.lixx", "PrivateZone": false }, "ResourceRecordSetCount": 14 } ], "DNSName": "example.com", "IsTruncated": false, "MaxItems": "100" }
You can search for the zone ID from the host zone name by using the command [aws route53 list-hosted-zones] that specifies the parameter [–query] as shown in the sample below. [1]
Please note that you need to add [.] To the end of the domain name specified in the –query condition. Example: [example.com] → [example.com.]
Sample 1:
aws route53 list-hosted-zones --query "HostedZones[?Name=='example.com.'].Id" --output text
To register / change / delete records, please use the AWS CLI command [aws route53 change-resource-record-sets] as shown in the sample below. [2]
Sample 2:
aws route53 change-resource-record-sets --hosted-zone-id <YOUR_HOSTED_ZONE_ID> --change-batch file://example.json
The contents of the [example.json] file should look like this:
{ "Comment": "optional comment about the changes in this change batch request", "Changes": [ { "Action": "CREATE", "ResourceRecordSet": { "Name": "example.com", "Type": "A", "TTL": 3600, "ResourceRecords": [ { "Value": "xx.x.x.xx" } ] } } ] }
References:
[1] list-hosted-zones
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53/list-hosted-zones.html
[2] change-resource-record-sets
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/route53/change-resource-record-sets.html