Want to pass header value of a WebRequest to SQS (either as token value or in attribute) from API Gateway

amazon-sqs, amazon-web-services, aws-api-gateway

Solution

I faced a similar issue recently,

I did the following changes in the integration request:

- I removed everything from query parameters

- Added Action and MessageBody in mapping templates

- Request body passthrough set to When no template matches the request Content- Type header

- Content Handling set to Passthrough

Below is the code snippet I added in Mapping Template:

Action=SendMessage&MessageBody={
  "data" : $input.json('$'),
  "headers": {
    #foreach($param in $input.params().header.keySet())
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end
    
    #end  
  }
}

Below is the screenshot for reference:

This worked for me and it started pushing headers along with body in the SQS.

Below is a sample message which is getting pushed in the queue:

{ "data" : {"body-key1":"body-value-1"}, "headers": { "header1": "value1" } }

So what's happening here is when I am sending a post request on queue URL without any query parameter it takes the body directly from the mapping template.

Hope this answer could help anyone.

Problem

I am getting a signature in WebHook in a particualar header. I would like to pass the same to SQS either in Token Body or Attribute. I have tried following configuration. It is not working. Please help Following are the details: ``` AWS Service : Simple Queue Service (SQS) HTTP method :POST Path override :Account/QueueName?Action=SendMessage Execution role :arn:aws:iam::Acc#:role Content Handling :Passthrough Body Mapping Templates : Content-Type : application/json { "MessageBody" : { "payload": $input.json('$'), "x-api-key" : "$input.params('x-api-key')" } } Instead of MessageBody, I also tried with "body". Response I get : { "Error": { "Code": "MissingParameter", "Message": "The request must contain the parameter MessageBody.", "Type": "Sender" }, "RequestId": "d5fc3acf-18dc-5379-9af2-6b4cc42358f3" } ``` What am I missing? Please help. I have spent almost whole day trying to figure it out. Thanks in Advance.

Original source

Related problems