18

I'm trying to create a TXT record in Route53 via the Amazon CLI for DNS-01 validation. Seems like I'm very close but possibly running into a CLI issue (or a formatting issue I don't see). As you can see, it's complaining about a value that should be in quotes, but is indeed in quotes already...

Command Line:

aws route53 change-resource-record-sets --hosted-zone-id ID_HERE --change-batch file://c:\dev\test1.json

JSON File:

{
"Changes": [
    {
        "Action": "UPSERT",
        "ResourceRecordSet": {
            "Name": "DOMAIN_NAME_HERE",
            "Type": "TXT",
            "TTL": 60,
            "ResourceRecords": [
                {
                    "Value": "test"
                }
            ]
        }
    }
]
}

Error:

An error occurred (InvalidChangeBatch) when calling the ChangeResourceRecordSets operation: Invalid Resource Record: FATAL problem: InvalidCharacterString (Value should be enclosed in quotation marks) encountered with 'test'
BRass
  • 3,698
  • 2
  • 28
  • 46

1 Answers1

32

Those quotes are the JSON quotes, and those are not the quotes they're looking for.

The JSON string "test" encodes the literal value test.

The JSON string "\"test\"" encodes the literal value "test".

(This is because in JSON, a literal " in a string is escaped with a leading \).

It sounds like they want actual, literal quotes included inside the value, so if you're building this JSON manually you probably want the latter: "Value": "\"test\"".

A JSON library should do this for you if you passed it the value with the leading and trailing " included.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427
  • Spot on. Thanks! Interesting that they don't want all string parameters provided with escaped quotes like this. – BRass Nov 22 '16 at 15:42
  • 5
    That's because this is a `TXT` record, which [is a quoted string, by definition](https://tools.ietf.org/html/rfc1464)... so Route 53 expects to see actual quotes inside the record. – Michael - sqlbot Nov 22 '16 at 19:08
  • *"A TXT record contains a space-separated list of double-quoted strings."* -- http://docs.aws.amazon.com/Route53/latest/DeveloperGuide/ResourceRecordTypes.html#TXTFormat – Michael - sqlbot Nov 22 '16 at 19:10
  • Makes sense now. Thanks again. – BRass Nov 28 '16 at 22:43
  • these are not the quotes you're lookin for... :). Thanks @Michael-sqlbot! Would've expected AWS to detect and automatically fix this – thiezn Sep 02 '20 at 15:06
  • @Michael-sqlbot And Amazon is, apparently, above making it easier for everyone else by simply detecting a predictable issue like this in their CLI tool and applying the required formatting. Hooray! – aroth Mar 02 '21 at 04:17
  • Confirming that this works with the shorthand syntax as well: `--change-batch 'Changes=[{Action=UPSERT,ResourceRecordSet={Name=some.domain,Type=TXT,TTL=300,ResourceRecords=[{Value="\"here goes the value\""}]}}]'` – Janaka Bandara Mar 05 '21 at 06:06
  • Helped! "ResourceRecords": [ { "Value": "\"123.cloudfront.net\"" } ] – Mindaugas K. Jan 27 '23 at 10:45