- Newest
- Most votes
- Most comments
The SQS sendMessage operation returns an XML-formatted response by default, which includes the MessageId of the message that was sent to the queue. If you want to return a different format, such as JSON, you will need to use a custom solution. One option would be to use an AWS Lambda function to transform the XML response to JSON before returning it to the API Gateway.
Another option would be to use a custom plugin to transform the XML response to JSON before returning it to the API Gateway. This can be done using a plugin such as the AWS SDK for Node.js, which includes a method for parsing XML to JSON.
Alternatively you can use the $util.parseXml() method to parse the XML response and convert it to a JSON object, which can then be used to set headers or the body of the API Gateway response.
You can use the $util.xml.toJson() method to convert the XML to JSON, and then use the $util.map() method to map the resulting JSON object to the desired headers or body of the API Gateway response.
Relevant content
- Accepted Answerasked 8 months ago
- asked 9 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 15 days ago
Thanks, I was worried the only option would be to insert a lambda between the endpoint and the queue.
Where would the custom plugin live? is that also within an lambda? I assume yes since it would need the AWS SDK.
Using
$util.xml.toJson()
and$util.xml.toJson()
don't appear to be valid mapping expressions for parameter mapping for HTTP Api but probably are for REST Apis.It's interesting that a REST API -> SQS integration doesn't require any manual transformations and returns JSON directly but HTTP API -> SQS integration returns xml with no option to transform.