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.

enter image description here enter image description here

+3


source to share


3 answers


I used the following pattern matching to just hide the quotes and it worked:




$ input.path ('$')

+5


source


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?

+4


source


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.

Method response: Method response

Integration response: Integration response

Here is a link to the original article: http://kennbrodhagen.net/2016/01/31/how-to-return-html-from-aws-api-gateway-lambda/

0


source







All Articles