I have a working AWS API Gateway Method Integration that returns a payload, I’d prefer it to return no payload at all as an HTTP 204 No Content response.
The CloudFormation definition of a working version of the method. It just delegates to SQS to send a message.
# The rest of the Cloudformation template is boiler-plate API Gateway and elided.
RestPost:
Type: AWS::ApiGateway::Method
Properties:
RestApiId: !Ref RestApi
ResourceId: !Ref RestResource
AuthorizationType: NONE # This method is public.
HttpMethod: POST
Integration:
Type: AWS
Credentials: !GetAtt Role.Arn
IntegrationHttpMethod: POST
Uri: !Sub arn:aws:apigateway:${AWS::Region}:sqs:path/${AWS::AccountId}/${Queue.QueueName}
PassthroughBehavior: NEVER
RequestParameters:
integration.request.header.Content-Type: "'application/x-www-form-urlencoded'"
RequestTemplates:
application/json: Action=SendMessage&MessageBody=$util.urlEncode($input.body)
IntegrationResponses:
- StatusCode: 200 # This, the first one, is also the default match, so the code here means nothing
ResponseTemplates:
application/json: |
{} ## a minimal JSON document
MethodResponses:
- StatusCode: 200 # This, the first one, is also the default match, so the code here means nothing
Enabling X-Ray has indeed shown that there is a fault in the method, but I cannot seem to extract any other useful information from it.
Change the ResponseTemplate
to
#set($context.responseOverride.status = 202)
{} ## a minimal JSON document
This works and correctly maps the status code from 200 OK to 202 Accepted.
Change the ResponseTemplate
to
#set($context.responseOverride.status = 204)
{} ## a minimal JSON document
This returns a 500 Internal Server Error.