File size: 1,372 Bytes
dc71c15 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#!/bin/bash
# Set variables
HOSTED_ZONE_ID="Z04320311ASMBEOMPIIN6" # Replace with your Hosted Zone ID
RECORD_NAME="verblaze.tlvtech.io" # Replace with your DNS record name
TTL=300 # Time to live for DNS record
TYPE="A" # Record type (A, CNAME, etc.)
# Command to get the desired output (example: getting your public IP address)
OUTPUT=$(curl -s http://checkip.amazonaws.com/)
# Validate the output
if [[ -z "$OUTPUT" ]]; then
echo "Error: No output from command"
exit 1
fi
# Create JSON payload for updating the DNS record
cat << EOF > /tmp/route53-record-update.json
{
"Comment": "Auto update DNS record via script",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "$RECORD_NAME",
"Type": "$TYPE",
"TTL": $TTL,
"ResourceRecords": [
{
"Value": "$OUTPUT"
}
]
}
}
]
}
EOF
# Update the Route 53 record
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --change-batch file:///tmp/route53-record-update.json
# Check if the update was successful
if [[ $? -eq 0 ]]; then
echo "DNS record updated successfully with value: $OUTPUT"
else
echo "Failed to update DNS record"
exit 1
fi
# Clean up the temporary file
rm /tmp/route53-record-update.json
|