John doe
John doe

Reputation: 3870

How to access twilio's request from the aws api gateway mapping template?

I want to access my twilio get request (body, method, query etc.) via the aws api gateway but i don't know what to put in my aws api gateway in the mapping template to process it.

Any help will be highly appreciated.

Thanks.

Upvotes: 0

Views: 328

Answers (2)

codeputer
codeputer

Reputation: 2018

This is the most complete answer for AWS API Gateway to convert a form URL encoded POST, to a JSON payload... Convert URL Encode to JSON NOTE: Scroll down to the last answer, as there are several updated to account for edge cases.

It's a lot of ceremony, using a language that I've never seen before, but at least it's readable. Far cry IMO from Azure functions where you simply get the request, and then manage it with the language that you are in.

This only gets you half way there however, you also have to add a mapping template to the Integration Response - but that template is simple and is referenced in the previous comment - repeated here for convenience

#set($inputRoot = $input.path('$'))
<?xml version="1.0" encoding="UTF-8"?>
<Response>
            $inputRoot
</Response> 

Since I'm using only responding to an SMS message - I added the following, and only returned a string from the function:

#set($inputRoot = $input.path('$'))
<?xml version="1.0" encoding="UTF-8"?>
<Response>
    <Message>
        <Body>
            $inputRoot
        </Body>
    </Message>
</Response> 

Upvotes: 0

Balaji
Balaji

Reputation: 1046

If you want the response from the endpoint to be passed through as-is, you can use pass through mapping. Otherwise, you can use the mapping templates to customize the method response. Here is the Mapping Template Reference for API Gateway. Please let us know if you have any specific questions.

Upvotes: 1

Related Questions