From bdbe4127244b7ec16c98d4aebcc58d77679ead40 Mon Sep 17 00:00:00 2001 From: Mehmet Nuri Deveci <5735811+mndeveci@users.noreply.github.com> Date: Mon, 9 May 2022 10:56:31 -0700 Subject: [PATCH] fix: raise InvalidEventException for incorrect Properties field usage for Api event type (#2393) --- .../plugins/api/implicit_http_api_plugin.py | 2 +- ...error_function_api_invalid_properties.yaml | 21 +++++++++++++++++++ ...error_function_api_invalid_properties.json | 3 +++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/translator/input/error_function_api_invalid_properties.yaml create mode 100644 tests/translator/output/error_function_api_invalid_properties.json diff --git a/samtranslator/plugins/api/implicit_http_api_plugin.py b/samtranslator/plugins/api/implicit_http_api_plugin.py index 8ea3a6cd0..78cb2a7bf 100644 --- a/samtranslator/plugins/api/implicit_http_api_plugin.py +++ b/samtranslator/plugins/api/implicit_http_api_plugin.py @@ -58,7 +58,7 @@ def _process_api_events( # api_events only contains HttpApi events event_properties = event.get("Properties", {}) - if event_properties and not isinstance(event_properties, dict): + if not isinstance(event_properties, dict): raise InvalidEventException( logicalId, "Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue.", diff --git a/tests/translator/input/error_function_api_invalid_properties.yaml b/tests/translator/input/error_function_api_invalid_properties.yaml new file mode 100644 index 000000000..1e50301dc --- /dev/null +++ b/tests/translator/input/error_function_api_invalid_properties.yaml @@ -0,0 +1,21 @@ +Resources: + Function: + Type: AWS::Serverless::Function + Properties: + Runtime: python3.7 + Handler: index.handler + CodeUri: s3://bucket/key + Events: + Api: + Type: HttpApi + Properties: '' + Function2: + Type: AWS::Serverless::Function + Properties: + Runtime: python3.7 + Handler: index.handler + CodeUri: s3://bucket/key + Events: + Api2: + Type: RestApi + Properties: '' diff --git a/tests/translator/output/error_function_api_invalid_properties.json b/tests/translator/output/error_function_api_invalid_properties.json new file mode 100644 index 000000000..7208a9047 --- /dev/null +++ b/tests/translator/output/error_function_api_invalid_properties.json @@ -0,0 +1,3 @@ +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [Api] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue." +} \ No newline at end of file