AWS API Gateway as Proxy for SQS - Data arrives without positive sign

Viewed 605

I created an API gateway that receives JSON data and posts it to SQS queue. My problem is: if I post data with a POSITIVE SIGNAL (+), for example, {"date": "25 + 2"} the positive signal is replaced by a space, the data arrives in the SQS queue like this: {"date": "25 2"}.

Although, if I send this same message {"date": "25+2"} through the AWS console, the message is received unchanged, with a plus sign.

Why?

Do I need to add additional configuration?

My API Gateway Configuration:

enter image description here

My Post:

curl --location --request POST 'https://xxxxxxxx.execute-api.us-east-1.amazonaws.com/yyyy' \
--header 'Content-Type: application/json' \
--data-raw '{"data": "25+2"}'

Data received in the SQS queue:

enter image description here

P.S: When I get this message through an application like .NET C#, the data also arrives without the positive signal.

1 Answers

After the help of a friend and carefully reading the AWS documentation, I found the solution.

The AWS SQS queue expects to receive the message in www-form-urlencoded format and not a JSON (or XML) format.

Therefore, we have two solutions for the case of the question:

  1. When calling the API already send the encoded message.

  2. Or... configure the template in API Gateway to convert the message received in the body to the application/x-www-form-urlencoded format, using the $util.urlEncode function, as shown below:

Mapping template:

Action=SendMessage&MessageBody=$util.urlEncode($input.body)
Related