Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS API Gateway : Convert response to XML

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?

like image 813
Himanshu Avatar asked Aug 16 '15 12:08

Himanshu


People also ask

Does API gateway support XML?

We quickly integrated the backend SOAP service from Gateway. But then, we realized some great limitations of AWS API GW for our use case: It does not support XML to JSON transformation. It does not parse XML content to modify it, though velocity scripting language provides a great deal of flexibility to modifying JSON.

Can API gateway return html?

Overview. In this tuorial you'll first create a Lambda placeholder function that returns HTML and bind it to an API in API Gateway. The placeholder function will return a hard-coded HTML string. Once you have the skeleton in place you can replace this function with a more sophisticated version.

How do I export API API gateway?

Export REST API using the API Gateway console From the stage configuration page in the API Gateway console, choose the Export tab and then one of the available options (Export as OpenAPI, Export as OpenAPI + API Gateway Integrations and Export as Postman) to download your API's OpenAPI definition.


1 Answers

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:

#set($root = $input.path('$'))
<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>
like image 66
James Avatar answered Oct 03 '22 06:10

James