Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions samtranslator/plugins/api/implicit_http_api_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ def _process_api_events(self, function, api_events, template, condition=None):
for logicalId, event in api_events.items():
# api_events only contains HttpApi events
event_properties = event.get("Properties", {})

if event_properties and 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.",
)

if not event_properties:
event["Properties"] = event_properties
self._add_implicit_api_id_if_necessary(event_properties)
Expand Down
6 changes: 6 additions & 0 deletions samtranslator/plugins/api/implicit_rest_api_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ def _process_api_events(self, function, api_events, template, condition=None):
if not event_properties:
continue

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.",
)

self._add_implicit_api_id_if_necessary(event_properties)

api_id = self._get_api_id(event_properties)
Expand Down
11 changes: 11 additions & 0 deletions tests/translator/input/error_function_invalid_api_event.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
Resources:
FunctionApiInvalidProperties:
Type: 'AWS::Serverless::Function'
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: hello.handler
Runtime: python2.7
Events:
ApiEvent:
Type: Api
Properties: '/hello' # NOTE: Should be an object no a string

FunctionApiNoMethod:
Type: 'AWS::Serverless::Function'
Properties:
Expand Down
12 changes: 12 additions & 0 deletions tests/translator/input/error_implicit_http_api_properties.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: nodejs12.x
Policies: AmazonDynamoDBFullAccess
Events:
Basic:
Type: HttpApi
Properties: /basic
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"errorMessage": "Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'."
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 4. Resource with id [FunctionApiMethodArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Method'. Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Method'. Resource with id [FunctionApiNoPath] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'. Resource with id [FunctionApiPathArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Path'."
}
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [FunctionApiInvalidProperties] is invalid. Event with id [ApiEvent] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue. Resource with id [FunctionApiMethodArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Method'. Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Method'. Resource with id [FunctionApiNoPath] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'. Resource with id [FunctionApiPathArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Path'."
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"errors": [
{
"errorMessage": "Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue."
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue."
}
1 change: 1 addition & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw
"error_http_api_invalid_openapi",
"error_http_api_tags",
"error_http_api_tags_def_uri",
"error_implicit_http_api_properties",
"error_implicit_http_api_method",
"error_implicit_http_api_path",
"error_http_api_event_multiple_same_path",
Expand Down