HTTP API Gateway -> SQS Response Mapping

0

I've added a HTTP API route integration that sends a message to an sqs queue. I would like to map the response to something other than xml in the api response. If the only option is to map to a response header that may work, but the only options to select a value from the sendMessage response is the use $response.body.<json_path> which will not work with xml.

Is there anyway to have this integration (sqs-sendMessage) not return xml ? If not, is there anyway to map an xml value to a response header or body? (without using a lambda in between the endpoint and queue)

1 Answer
0

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.

profile picture
answered a year 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.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions