AWS API Gateway : Convert response to XML

Question:

I am getting a string value (xml to string) from lambda backend which should be returned to end user in application/xml format. How can I achieve this?

Answer:

You can specify an Integration Response that returns XML, along with a mapping template to format XML using the object returned from Lambda.

Sample Integration Response

I do not believe there is a default format conversion to XML. A simple mapping template might be like this:


))
<stuff>
<message>$root.message</message>
<sourceIp>$context.identity.sourceIp</sourceIp>
<outputs>
#foreach($key in $root.keySet())
<output>
<key>$key</key>
<value>$root.get($key)</value>
</output>
#end
</outputs>
</stuff>

Leave a Reply