| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /home/ubuntu/.scripts/ |
Upload File : |
#!/usr/bin/env bash
#
# Bulk-update Route53 records that point at OLD_IP → NEW_IP.
# Run during the EC2 resize window per the t3.large walkthrough.
#
# Usage:
# /home/ubuntu/.scripts/route53-swap-ip.sh OLD_IP NEW_IP [--apply]
#
# Without --apply: prints the change set as a dry-run.
# With --apply: pushes the changes to Route53.
set -euo pipefail
OLD_IP="${1:?need OLD_IP as first arg}"
NEW_IP="${2:?need NEW_IP as second arg}"
APPLY="${3:-}"
echo "Audit: records currently pointing at ${OLD_IP}"
TMP=$(mktemp /tmp/route53-swap.XXXX)
trap 'rm -f $TMP' EXIT
for zone_pair in $(aws route53 list-hosted-zones --query "HostedZones[].[Id,Name]" --output text | awk '{print $1 "|" $2}'); do
zone_id="${zone_pair%|*}"
zone_name="${zone_pair#*|}"
aws route53 list-resource-record-sets --hosted-zone-id "$zone_id" \
--query "ResourceRecordSets[?ResourceRecords && contains(ResourceRecords[].Value, '${OLD_IP}')].{name:Name, ttl:TTL, type:Type}" \
--output json 2>/dev/null \
| python3 -c "
import json, sys
rs = json.load(sys.stdin)
for r in rs:
print('${zone_id}|' + r['name'] + '|' + r['type'] + '|' + str(r['ttl']))
" >> "$TMP"
done
count=$(wc -l < "$TMP")
echo "Found ${count} records to update."
if [ "$count" -eq 0 ]; then
echo "Nothing to do."
exit 0
fi
cat "$TMP" | while IFS='|' read zone_id name type ttl; do
printf ' %-40s %s\n' "$name ($type, TTL=$ttl)" "$OLD_IP → $NEW_IP"
done
if [ "$APPLY" != "--apply" ]; then
echo
echo "DRY-RUN. Re-run with --apply to push."
exit 0
fi
echo
echo "Applying..."
while IFS='|' read zone_id name type ttl; do
BATCH=$(cat <<JSON
{"Changes":[{"Action":"UPSERT","ResourceRecordSet":{"Name":"${name}","Type":"${type}","TTL":${ttl},"ResourceRecords":[{"Value":"${NEW_IP}"}]}}]}
JSON
)
result=$(aws route53 change-resource-record-sets --hosted-zone-id "$zone_id" --change-batch "$BATCH" 2>&1)
change_id=$(echo "$result" | python3 -c "import json,sys; print(json.load(sys.stdin)['ChangeInfo']['Id'])" 2>/dev/null || echo "ERR")
printf ' %-40s %s\n' "$name" "$change_id"
done < "$TMP"
echo
echo "All UPSERTs issued. DNS propagation begins now (max TTL was 300s = 5min)."