Trying to resolve the Twilio 12300 Error: Invalid Content-Type caused when deploying a Lambda (Serverless) app using AWS's API Gateway (GET) and CloudFormation via the aws cli
and Swagger.
I have the Integration Response Body Mapping Template > Content-Type set to application/xml
and the template
#set($inputRoot = $input.path('S'))
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Message>
<Body>
$inputRoot
</Body>
</Message>
</Response>
Examining the actual Response Body from Twilio logs, the output matches the template, returning an appropriately formatted XML response.
However, the Response Header > Content-Type still returns application/json
.
It seems as if this requires a setting change within Method Response, but either the AWS API Gateway dashboard and/or the Swagger API doesn't allow for me to set the Header > Content-Type to application/xml
.
Below is the swagger.yaml
file
---
swagger: "2.0"
info:
version: "2016-12-20T18:27:47Z"
title: "twilio-apigateway"
basePath: "/Prod"
schemes:
- "https"
paths:
/addphoto:
get:
consumes:
- "application/json"
produces:
- "application/xml"
responses:
200:
description: "200 response"
x-amazon-apigateway-integration:
responses:
default:
statusCode: "200"
responseTemplates:
application/xml: "#set($inputRoot = $input.path('$'))\n<?xml version=\"\
1.0\" encoding=\"UTF-8\"?>\n<Response>\n <Message>\n <Body>\n\
\ $inputRoot\n </Body>\n </Message>\n</Response> "
requestTemplates:
application/json: "{\n \"body\" : \"$input.params('Body')\",\n \"\
fromNumber\" : \"$input.params('From')\",\n \"image\" : \"$input.params('MediaUrl0')\"\
,\n \"numMedia\" : \"$input.params('NumMedia')\"\n}"
# NOTE: Replace <<region>> and <<account>> fields
uri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:<<cccount_id>>:function:${stageVariables.LambdaFunctionName}/invocations
passthroughBehavior: "when_no_templates"
httpMethod: "POST"
contentHandling: "CONVERT_TO_TEXT"
type: "aws"
Would love some help here from anyone who has resolved this issue. Although it seems this is a known issue (Twilio requiring XML format) and the AWS Swagger API being limited in some ways, which may result in an unresolvable state.
Additional references:
http://boto3.readthedocs.io/en/latest/reference/services/apigateway.html
application/json
too). If you've requested it to be a GET request the parameters will come as URL query parameters. – philnash