Scenario:
I want to have an AWS API gateway route that forwards the HTTP POST call request body to the AWS SQS service. I successfully did that using the new AWS console interface for API gateway and Amazon Simple Queue Service as the integration target.
Now, the problem is I want to send a specific request header value as Message attributes to SQS, but the acceptable format in the console is ambiguous as hell!
I tried whatever found on the documents and threads and books that I could find and even tried some similar notation from other services value format, but nothing worked.
When I tried and set different values for the Message attribute like the following, it starts returning 400 error status code in response to the HTTP request that was working before.
I just want to send a request header along the request body to the SQS so I have essential data that is stored on the request header to process the message.
tried values:
- $request.header.valueX
- {"somename":"$request.header.valueX"}
- {"Name":"somename","Value":{"DataType":"String","StringValue":"$request.header.valueX"}}
none of the above formats are acceptable in AWS Console for Message Attribute (optional) advance setting in API gateway integration for SQS.
I could not find any proper value format for Message Attribute.
Thank you very much
Update:
I tried a solution that worked for me:
because I have control over clients of the service, I defined a new custom header (sample1) with a value in the following format:
{"CUSTOM-ATTRIBUTE-NAME": {"DataType": "String", "StringValue": "CUSTOM-ATTRIBUTE-VALUE"}}
In the Message attribute - optional in the SQS integration page on API Gateway, I set the value to $request.header.sample1
the custom-attribute-name will be the SQS message attribute name and the CUSTOM-ATTRIBUTE-VALUE will be the value.
now when I receive the message from SQS, I have both the complete request message body and my custom header in the message attributes.
