shell-base/function/archive/aws-recordset

87 lines
1.8 KiB
Bash

#!/bin/bash
function aws-get-zone-record () {
local record
echo get record $1 $(get-domain $1)
record=$(
aws route53 list-resource-record-sets \
--hosted-zone-id $(aws-get-zone-id $1)
)
echo "$record"
}
function aws-get-zone-record-prop () {
local record
record=$(aws-get-zone-record $1)
local res
res=$(get-prop-value "$record" $2)
echo "$res"
}
function aws-get-zone-record-value () {
local record
record=$(aws-get-zone-record $1)
local res
res=$(get-prop-value "$record" "ResourceRecords[0].Value")
echo "$res"
}
function aws-update-zone-record-value () {
if [ "$#" -ne 2 ]; then
echo "Both recordset and value required"
exit 0
fi
RECORDSET=$1
VALUE=$2
COMMENT=${3:-"Updating Record"}
RECORD=$(aws-get-zone-record "$RECORDSET")
echo the reccord $RECORD
# ZONENAME=$(get-domain $RECORDSET)
ZONEID=$(aws-get-zone-id "$(get-domain $RECORDSET )")
# The Time-To-Live of this recordset
# echo Zone Name and ID for recordset $RECORDSET $ZONENAME $ZONEID
# TTL=60 # call this later with increase
# Fill a temp file with valid JSON
CHANGE="{
\"Comment\":\"$COMMENT\",
\"Changes\":[
{
\"Action\":\"UPSERT\",
\"ResourceRecordSet\":{
\"ResourceRecords\":[
{
\"Value\":\"$VALUE\"
}
],
\"Name\":\"$RECORDSET\",
\"Type\":\"$(get-prop-value "$RECORD" Type)\",
\"TTL\":\"$(get-prop-value "$RECORD" TTL)\"
}
}
]
}
"
echo updating record with
batch=\'${CHANGE}\'
echo batch
# Update the Hosted Zone record
CMD="aws route53 change-resource-record-sets
--hosted-zone-id ${ZONEID}
--change-batch $batch
"
echo "${CMD}"
local res
res=$($CMD)
echo "$res"
# echo confirm change $(aws-get-zone-record-value $RECORDSET)
# end function
}