How to change IP in route 53 via script

I am using AWS's route53 for my DNS registration and configuration. It is the best DNS service that I am aware of from a stability and usability for a fair price.

The problem at hand is how to update the A-record to match my internal IP address. First, lets get the A-record from route53. Setting up awscli on the box is assumed to be working for this setup []. you can test to see if the AWS command is fetching your settings with the following

aws route53 list-resource-record-sets --hosted-zone-id ZEMINSERTMYID

Now get your current A-record in route53 with the following command

aws route53 list-resource-record-sets --hosted-zone-id ZEMINSERTMYID --query "ResourceRecordSets[?Type == 'A'].ResourceRecords[0].Value" --output text

Now for the WAN IP. I am using pfsense for routing so you will most likely need to modify this if you are not.

ifconfig em1 | grep "inet " | awk '{print $2}'

If the WAN IP doesnt match the AWS A-record, then change it with the following. Be sure to change the value of the ResourceRecords to your WAN IP.

aws route53 change-resource-record-sets \
  --hosted-zone-id ZEM7KVE6CM3IE \
  --cli-input-json \
      { "Comment": "Update A record with current IP addr", \
        "Changes": [ { "Action": "UPSERT", "ResourceRecordSet": { \
            "Name": "", \
            "Type": "A", \
            "TTL": 30, \
            "ResourceRecords": [ { "Value": "XXX.XXX.XXX.XXX" } ] 
      } } ] }