AWS Lambda's Response to API Gateway
I have a lambda function that generates some text. This is for a simple Twilio app
<Say>Welcome to your conference room!</Say>
<Dial>
<Conference beep="true">waitingRoom</Conference>
</Dial>
When I make a POST request using the mail manager, it outputs exactly this. but i have two problems:
- The headers are returned in application / json and I need it as text / xml.
- When I make a POST request from Twilio I get 502 Bad Gateway
I know it has to do something about displaying the incoming parameters and also display the response from Lambda back to the API gateway as text / xml. But I cannot figure out how to do this.
source to share
I'm glad to be not the only one struggling with AWS Api Gateway :)
As far as I know, AWS Api Gateway is mainly JSON oriented. If you can change the content of the returned response (using JSON), you might be able to solve your problem:
{"say": "Welcome to your conference room!",
"dial": [{
"conference": [{
"beep": "true",
"name": "waitingRoom"
}]
}
]}
You can then match this content using the mapping template function (in the integration response screen) by adding a template with a content type set to "application / json" and a template template configured to:
<Say>$input.json('say')</Say>
<Dial>
<Conference beep="$input.json('dial.conference.beep')">$input.json('dial.conference.name')</Conference>
</Dial>
Does this help you or am I missing something?
source to share
To change the Content-Type in a response, you need to configure 2 scopes in the API: Method Response and Integration Response.
In the Method response, you add a Content-Type response header for your 200 status code.
In Integration Response, you open the 200 response and set the Content-Type to text / xml.
Here are some screenshots from an article I wrote about returning html content. Your case sounds a lot like you want to return a string type that contains xml and has the correct Content-Type header.
Here is a link to the original article: http://kennbrodhagen.net/2016/01/31/how-to-return-html-from-aws-api-gateway-lambda/
source to share