1
votes

Is there a way to set a GatewayResponse for an API Gateway in Cloudformation, with an empty response body (and ideally without response Content-Type)

I have tried with something like this:

  InvalidApiKeyResponse:
    Type: AWS::ApiGateway::GatewayResponse
    Properties:
      ResponseType: INVALID_API_KEY
      RestApiId: !Ref RestApi
      StatusCode: 403

but it still returns the default application/json response.

In the AWS dashboard, when I try to set an empty response I get the following error: Invalid null or empty value in responseTemplates

1

1 Answers

0
votes

Try adding in the ResponseTemplates piece below.

GatewayResponse:
    Type: AWS::ApiGateway::GatewayResponse
    Properties:
      ResponseTemplates:
          application/json: ""
      ResponseType: INVALID_API_KEY
      RestApiId: !Ref RestApi
      StatusCode: 403