diff --git a/moto/apigateway/models.py b/moto/apigateway/models.py index d520e50ae..eea3cbfeb 100644 --- a/moto/apigateway/models.py +++ b/moto/apigateway/models.py @@ -29,7 +29,6 @@ from .exceptions import ( InvalidIntegrationArn, InvalidHttpEndpoint, InvalidResourcePathException, - InvalidRequestInput, AuthorizerNotFoundException, StageNotFoundException, RoleNotSpecified, @@ -1099,8 +1098,6 @@ class APIGatewayBackend(BaseBackend): response_templates, content_handling, ): - if response_templates is None: - raise InvalidRequestInput() integration = self.get_integration(function_id, resource_id, method_type) integration_response = integration.create_integration_response( status_code, selection_pattern, response_templates, content_handling diff --git a/moto/apigateway/responses.py b/moto/apigateway/responses.py index 1f7effcea..563db98b7 100644 --- a/moto/apigateway/responses.py +++ b/moto/apigateway/responses.py @@ -19,6 +19,7 @@ from .exceptions import ( RestAPINotFound, ModelNotFound, ApiKeyValueMinLength, + InvalidRequestInput, ) API_KEY_SOURCES = ["AUTHORIZER", "HEADER"] @@ -369,6 +370,9 @@ class APIGatewayResponse(BaseResponse): function_id, resource_id, method_type, status_code ) elif self.method == "PUT": + if not self.body: + raise InvalidRequestInput() + selection_pattern = self._get_param("selectionPattern") response_templates = self._get_param("responseTemplates") content_handling = self._get_param("contentHandling") diff --git a/tests/test_apigateway/test_apigateway.py b/tests/test_apigateway/test_apigateway.py index 481c39bfb..090e30f9b 100644 --- a/tests/test_apigateway/test_apigateway.py +++ b/tests/test_apigateway/test_apigateway.py @@ -1279,6 +1279,7 @@ def test_put_integration_response_requires_responseTemplate(): ) ex.value.response["Error"]["Code"].should.equal("BadRequestException") ex.value.response["Error"]["Message"].should.equal("Invalid request input") + # Works fine if responseTemplate is defined client.put_integration_response( restApiId=api_id,