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
13 changes: 7 additions & 6 deletions samtranslator/model/eventsources/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,13 @@ def _add_swagger_integration(self, api, function):
'because it wasn\'t defined in the API\'s Authorizers.'.format(
authorizer=method_authorizer, method=self.Method, path=self.Path))

if method_authorizer == 'NONE' and not api_auth.get('DefaultAuthorizer'):
raise InvalidEventException(
self.relative_id,
'Unable to set Authorizer on API method [{method}] for path [{path}] because \'NONE\' '
'is only a valid value when a DefaultAuthorizer on the API is specified.'.format(
method=self.Method, path=self.Path))
if method_authorizer == 'NONE':
if not api_auth or not api_auth.get('DefaultAuthorizer'):
raise InvalidEventException(
self.relative_id,
'Unable to set Authorizer on API method [{method}] for path [{path}] because \'NONE\' '
'is only a valid value when a DefaultAuthorizer on the API is specified.'.format(
method=self.Method, path=self.Path))

apikey_required_setting = self.Auth.get('ApiKeyRequired')
apikey_required_setting_is_false = apikey_required_setting is not None and not apikey_required_setting
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: index.handler
Runtime: python3.7
Events:
HttpGetUserGroupIdUserId:
Type: Api
Properties:
Path: '/users/{groupId}/{userId}'
Method: GET
Auth:
Authorizer: "NONE"
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"errors": [{"errorMessage": "Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified."}],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified."
}
3 changes: 2 additions & 1 deletion tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,8 @@ def _generate_new_deployment_hash(self, logical_id, dict_to_hash, rest_api_to_sw
'error_api_with_invalid_open_api_version_type',
'error_api_with_custom_domains_invalid',
'error_api_with_custom_domains_route53_invalid',
'error_api_event_import_vaule_reference'
'error_api_event_import_vaule_reference',
'error_function_with_method_auth_and_no_api_auth'
])
@patch('boto3.session.Session.region_name', 'ap-southeast-1')
@patch('samtranslator.plugins.application.serverless_app_plugin.ServerlessAppPlugin._sar_service_call', mock_sar_service_call)
Expand Down