Skip to content
Open
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
10 changes: 10 additions & 0 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class ZappaCLI(object):
environment_variables = None
authorizer = None
aws_kms_key_arn = ''
web_socket_handler = None

cognito_authorizer_path = '/'

Expand Down Expand Up @@ -1820,6 +1821,9 @@ def load_settings(self, settings_file=None, session=None):
self.aws_kms_key_arn = self.stage_config.get('aws_kms_key_arn', '')
self.cognito_authorizer_path = self.stage_config.get('cognito_authorizer_path', '/')

# custom zappa settings key for web socket
self.web_socket_handler = self.stage_config.get('web_socket_handler')

desired_role_name = self.lambda_name + "-ZappaLambdaExecutionRole"
self.zappa = Zappa( boto_session=session,
profile_name=self.profile_name,
Expand Down Expand Up @@ -2090,6 +2094,12 @@ def create_package(self, output=None):
if authorizer_function:
settings_s += "AUTHORIZER_FUNCTION='{0!s}'\n".format(authorizer_function)

# web socket function
if self.web_socket_handler:
settings_s += "WEB_SOCKET_HANDLER='{0!s}'\n".format(
self.web_socket_handler)
else:
settings_s += "WEB_SOCKET_HANDLER=None\n"

# Copy our Django app into root of our package.
# It doesn't work otherwise.
Expand Down
14 changes: 14 additions & 0 deletions zappa/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,20 @@ def handler(self, event, context):
logger.error("Cannot find a function to process the authorization request.")
raise Exception('Unauthorized')

# this is a web socket event
elif event.get('requestContext') and \
event['requestContext'].get('connectionId'):
whole_function = self.settings.WEB_SOCKET_HANDLER
if whole_function:
app_function = self.import_module_and_get_function(
whole_function)
result = self.run_function(app_function, event, context)
return result
else:
logger.error(
"Cannot find a function to process the web socket request.")
raise Exception('Web socket request handler not found')

# Normal web app flow
try:
# Timing
Expand Down