list all hosted zones
aws --profile ${PROFILE} route53 list-hosted-zones --query "HostedZones[*].[Id,Name]" --output table
check configured record
aws --profile ${PROFILE} route53 list-resource-record-sets --hosted-zone-id 'Z27W91AKJ9OIGQ' --query "ResourceRecordSets[?Name == 'FQDN.']"
test record via test-dns-answer query
aws --profile ${PROFILE} route53 test-dns-answer --hosted-zone-id 'Z27W91AKJ9OIGQ' --record-name FQDN --record-type A
update dns record
aws --profile ${PROFILE} route53 change-resource-record-sets --hosted-zone-id 'Z2DNEX23O12IPI' --change-batch file://xxx.json
where xxx.json is defined as
{
"Comment": "CREATE/DELETE/UPSERT a record ",
"Changes": [{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "FQDN",
"Type": "A",
"TTL": 300,
"ResourceRecords": [{ "Value": "52.71.252.50"}]
}
}]
}
function for updating records
function change_route53 ()
{
resourcerecordset=$(aws --profile $1 route53 list-resource-record-sets --hosted-zone-id $2 --query "ResourceRecordSets[?Name == '$3.']" | jq -c .[])
updatedresourcerecordset=$(echo $resourcerecordset | jq -c '.ResourceRecords[].Value = '\"$4\"'')
echo "<<< Updating record: $resourcerecordset >>>"
aws --profile $1 route53 change-resource-record-sets --hosted-zone-id $2 --change-batch '{"Comment": "UPSERT a record ","Changes":[{"Action":"UPSERT","ResourceRecordSet":'"$updatedresourcerecordset"'}]}' --output text --query 'ChangeInfo.Id'
}