0

I have been trying to push data into AWS SQS using AWS API Gateway, the data I send is in the form of application/x-www-form-urlencoded.

And it looks somewhat like this:

fruits[]: apple
fruits[]: mango
fruits[]: banana
season: summer

Now when I poll the data from AWS SQS, I see only fruits[]=apple has been stored and all others are ignored.

This is my current mapping template to push in SQS:

Action=SendMessage&MessageBody=$input.body

Looks like it has multiple $input.body but if that is the case then its kinda impossible to capture random data coming in.

I am new to AWS API Gateway, thanks in advance. :D

Satnam Sandhu
  • 610
  • 1
  • 10
  • 25

2 Answers2

4

After a lot of research and stuff, I was able to decipher this mystery.

the value of $input.body is:

fruits[]=apple&fruits[]=mango&fruits[]=banana&season=summer

Now only MessageBody is pushed in SQS, so according to my template, the resulting query string which was forming, was:

Action=SendMessage&MessageBody=fruits[]=apple&fruits[]=mango&fruits[]=banana&season=summer

only fruits[]=apple is falling under MessageBody and all other becomes separate query objects and hence were ignored.

I just had to tweak the template to:

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

So the resulting query string does not include any more & or = and every thing falls under MessageBody

Edits are welcomed

Satnam Sandhu
  • 610
  • 1
  • 10
  • 25
0

try this

Request:

POST apigateway/stage/resource?query=test
{
  "season": "summer",
  "list": [apple,mango,banana]
}

Mapping:

#set($inputRoot = $input.path('$'))
{
  "query": "$input.params('query')",
  "id": "$inputRoot.season",
  "list": $inputRoot.list
}
vaquar khan
  • 10,864
  • 5
  • 72
  • 96