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?
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.
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.
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.
You can specify an Integration Response that returns XML, along with a mapping template to format XML using the object returned from Lambda.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With