diff --git a/lambdas/backend/src/constants.py b/lambdas/backend/src/constants.py index 3e571191a..d6aa8c6e2 100644 --- a/lambdas/backend/src/constants.py +++ b/lambdas/backend/src/constants.py @@ -2,4 +2,4 @@ GENERIC_SERVER_ERROR_DIAGNOSTICS_MESSAGE = "Unable to process request. Issue may be transient." # Maximum response size for an AWS Lambda function -MAX_RESPONSE_SIZE_BYTES = 6 * 1024 * 1024 +MAX_SEARCH_RESPONSE_SIZE_BYTES = 1 * 1024 * 1024 diff --git a/lambdas/backend/src/controller/fhir_controller.py b/lambdas/backend/src/controller/fhir_controller.py index dda898669..6d271a2ab 100644 --- a/lambdas/backend/src/controller/fhir_controller.py +++ b/lambdas/backend/src/controller/fhir_controller.py @@ -11,7 +11,7 @@ from fhir.resources.R4B.identifier import Identifier from common.get_service_url import get_service_url -from constants import MAX_RESPONSE_SIZE_BYTES +from constants import MAX_SEARCH_RESPONSE_SIZE_BYTES from controller.aws_apig_event_utils import ( get_multi_value_query_params, get_path_parameter, @@ -213,7 +213,7 @@ def _search_immunizations_by_target_disease(self, search_params: dict[str, list[ def _create_search_response(self, search_bundle: Bundle) -> dict: search_response_json = search_bundle.json(use_decimal=True) - if len(search_response_json) > MAX_RESPONSE_SIZE_BYTES: + if len(search_response_json) > MAX_SEARCH_RESPONSE_SIZE_BYTES: raise TooManyResultsError("Search returned too many results. Please narrow down the search") prepared_search_bundle = self._prepare_search_bundle(search_response_json) diff --git a/lambdas/backend/tests/controller/test_fhir_controller.py b/lambdas/backend/tests/controller/test_fhir_controller.py index e8afb7990..72cff2af7 100644 --- a/lambdas/backend/tests/controller/test_fhir_controller.py +++ b/lambdas/backend/tests/controller/test_fhir_controller.py @@ -1207,7 +1207,7 @@ def test_search_immunizations_returns_a_validation_error_when_optional_params_in ) self.service.search_immunizations.assert_not_called() - @patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5) + @patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5) def test_search_immunizations_raises_error_if_too_many_results_found(self): """it should return an error if there are too many results in the response for Lambda to handle. In reality, highly unlikely. If a concern, pagination should be implemented.""" diff --git a/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py b/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py index d9e62b39c..dce6cbef6 100644 --- a/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py +++ b/lambdas/backend/tests/controller/test_fhir_controller_target_disease.py @@ -288,7 +288,7 @@ def test_search_by_target_disease_with_mixed_valid_and_invalid_returns_200_with_ self.assertIn("invalid-no-pipe", call_args[1]["invalid_target_diseases"][0]) self.assertIn("Invalid format", call_args[1]["invalid_target_diseases"][0]) - @patch("controller.fhir_controller.MAX_RESPONSE_SIZE_BYTES", 5) + @patch("controller.fhir_controller.MAX_SEARCH_RESPONSE_SIZE_BYTES", 5) def test_search_by_target_disease_returns_400_when_response_too_large(self): """it should return the same narrow-the-search error for oversized target-disease searches""" self.mock_redis.hget.side_effect = self._hget_target_disease_codes_and_mmr