Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Quotes Converting to Special Characters using AWS CLI

I am making SES Templates using the AWS CLI and having issues with single quotes converting to special characters when the emails are sent.

This also happens when doing a DynamoDB put item operation using the CLI when a string contains a single quote within it.

I've tried backslashes, wrapping the quote in double quotes then escaping it etc.

aws ses send-bulk-templated-email --cli-input-json file://test.json aws dynamodb put-item --table-name TABLE --item file://item.json

Item/Test Example (snippets of the json):

test: "SubjectPart":"Happy birthday! Get more involved in managing your healthcare now that you're 18"

item: "S": "Now that you're 18"

Output:

Happy birthday! Get more involved in managing your healthcare now that you’re 18

and

Now that you’re 18

Expected:

Happy birthday! Get more involved in managing your healthcare now that you're 18

and

Now that you're 18

like image 969
Justin Twarog Avatar asked Jan 23 '26 20:01

Justin Twarog


1 Answers

Assuming that you're using Linux or Mac, with the bash shell ...

Here is an example of how to escape quote characters when using the awscli:

aws dynamodb put-item \
    --table mytable \
    --item '{"id":{"S":"1"}, "name":{"S":"Fred'\''s Garage"}}'

Here is a second way:

aws dynamodb put-item \
    --table mytable \
    --item $'{"id":{"S":"1"}, "name":{"S":"Fred\'s Garage"}}'

In the latter example, words of the form $'string' are treated specially and allow you to quote certain characters.

like image 105
jarmod Avatar answered Jan 25 '26 09:01

jarmod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!