Skip to content

Instantly share code, notes, and snippets.

@kulp
Created March 6, 2016 02:59
Show Gist options
  • Save kulp/7c3c33e8b8b70252efe6 to your computer and use it in GitHub Desktop.
Save kulp/7c3c33e8b8b70252efe6 to your computer and use it in GitHub Desktop.

Revisions

  1. kulp created this gist Mar 6, 2016.
    35 changes: 35 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    #!/bin/sh -e
    HOSTED_ZONE_IP=/hostedzone/CHANGEME
    DOMAIN=CHANGEME
    TTL=300

    my_ip=$HOME/.my_ip
    IP=$(dig +short myip.opendns.com @resolver1.opendns.com)
    if [ "$IP" = "$(cat $my_ip)" ]
    then
    exit 0
    fi

    json=$(cat <<EOF
    {
    "Changes": [
    {
    "Action": "UPSERT",
    "ResourceRecordSet": {
    "Name": "$DOMAIN",
    "Type": "A",
    "TTL": $TTL,
    "ResourceRecords": [
    {
    "Value": "$IP"
    }
    ]
    }
    }
    ]
    }
    EOF
    )

    aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_IP --change-batch "$json"
    echo "$IP" > $my_ip