Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Lambda send 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 postman it outputs exactly that. but I have two problems:

  1. The headers comes back at application/json, and I need it as text/xml.
  2. When I make the POST request from Twilio I get 502 Bad Gateway

I know it has to do something with the incoming params mapping and also mapping the response from Lambda back to the API Gateway as text/xml. But I can;t figure out how to do this.

enter image description hereenter image description here

like image 679
ecorvo Avatar asked Jan 07 '23 21:01

ecorvo


2 Answers

I used the following template mapping to basically just strip the quotes and it worked:


$input.path('$')

like image 59
Clearly Avatar answered Jan 16 '23 21:01

Clearly


I am glad not to be the only one struggling with AWS Api Gateway :)

As far as I know, AWS Api Gateway is mostly JSON oriented. If you can change the content of the response returned (using JSON), maybe you could resolve your problem :

{"say": "Welcome to your conference room!",
 "dial": [{
        "conference": [{
                "beep": "true",
                "name": "waitingRoom"
        }]
    }
]}

You could then map this content using the mapping template feature (in the Integration response screen), by adding a template with a content-type set to "application/json", and a mapping-template set 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 I am missing something ?

like image 27
Francis Toth Avatar answered Jan 16 '23 22:01

Francis Toth