diff --git a/dnsapi/dns_aws.sh b/dnsapi/dns_aws.sh
index bbc5428..33e7e70 100755
--- a/dnsapi/dns_aws.sh
+++ b/dnsapi/dns_aws.sh
@@ -42,7 +42,26 @@ dns_aws_add() {
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
- _aws_tmpl_xml="CREATE$fulldomainTXT300\"$txtvalue\""
+ _info "Geting existing records for $fulldomain"
+ if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
+ return 1
+ fi
+
+ if _contains "$response" "$fulldomain."; then
+ _resource_record="$(echo "$response" | _egrep_o "" | sed "s///" | sed "s###")"
+ _debug "_resource_record" "$_resource_record"
+ else
+ _debug "single new add"
+ fi
+
+ if [ "$_resource_record" ] && _contains "$response" "$txtvalue"; then
+ _info "The txt record already exists, skip"
+ return 0
+ fi
+
+ _debug "Adding records"
+
+ _aws_tmpl_xml="UPSERT$fulldomainTXT300$_resource_record\"$txtvalue\""
if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
_info "txt record updated success."
@@ -68,7 +87,20 @@ dns_aws_rm() {
_debug _sub_domain "$_sub_domain"
_debug _domain "$_domain"
- _aws_tmpl_xml="DELETE\"$txtvalue\"$fulldomain.TXT300"
+ _info "Geting existing records for $fulldomain"
+ if ! aws_rest GET "2013-04-01$_domain_id/rrset" "name=$fulldomain&type=TXT"; then
+ return 1
+ fi
+
+ if _contains "$response" "$fulldomain."; then
+ _resource_record="$(echo "$response" | _egrep_o "" | sed "s///" | sed "s###")"
+ _debug "_resource_record" "$_resource_record"
+ else
+ _debug "no records exists, skip"
+ return 0
+ fi
+
+ _aws_tmpl_xml="DELETE$_resource_record$fulldomain.TXT300"
if aws_rest POST "2013-04-01$_domain_id/rrset/" "" "$_aws_tmpl_xml" && _contains "$response" "ChangeResourceRecordSetsResponse"; then
_info "txt record deleted success."
@@ -87,7 +119,6 @@ _get_root() {
p=1
if aws_rest GET "2013-04-01/hostedzone"; then
- _debug "response" "$response"
while true; do
h=$(printf "%s" "$domain" | cut -d . -f $i-100)
_debug2 "Checking domain: $h"
@@ -236,6 +267,7 @@ aws_rest() {
fi
_ret="$?"
+ _debug2 response "$response"
if [ "$_ret" = "0" ]; then
if _contains "$response" "