Skip to content

Commit bbd25a7

Browse files
authored
Merge pull request #115 from gridsmartercities/fix_pyflakes_issue
Disabled pyflakes warning for 'ApiGatewayManagementApi', and added mi…
2 parents 1e3a327 + bfebe22 commit bbd25a7

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

aws_lambda_decorators/decorators.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,26 @@ def update_header(headers, header_name, value, value_type):
338338

339339

340340
def push_ws_errors(websocket_endpoint_url: str):
341+
"""
342+
Handles and pushes any unsuccessful responses as errors to the calling client via websockets
343+
344+
Usage:
345+
@push_ws_errors('https://api_id.execute_id.region.amazonaws.com/Prod')
346+
@handle_all_exceptions()
347+
def handler(event, context):
348+
return {
349+
'statusCode': 400,
350+
'body': {
351+
'message': 'Bad request'
352+
}
353+
}
354+
355+
Args:
356+
websocket_endpoint_url (str): The api gateway connection URL
357+
358+
Returns:
359+
the original response from the lambda handler
360+
"""
341361
def decorator(func):
342362
def wrapper(*args, **kwargs):
343363
connection_id = find_websocket_connection_id(args)
@@ -365,6 +385,23 @@ def wrapper(*args, **kwargs):
365385

366386

367387
def push_ws_response(websocket_endpoint_url: str):
388+
"""
389+
Handles and pushes all responses to the calling client via websockets
390+
391+
Usage:
392+
@push_ws_response('https://api_id.execute_id.region.amazonaws.com/Prod')
393+
def handler(event, context):
394+
return {
395+
'statusCode': 200,
396+
'body': 'Hello, world!'
397+
}
398+
399+
Args:
400+
websocket_endpoint_url (str): The api gateway connection URL
401+
402+
Returns:
403+
the original response from the lambda handler
404+
"""
368405
def decorator(func):
369406
def wrapper(*args, **kwargs):
370407
connection_id = find_websocket_connection_id(args)

aws_lambda_decorators/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def find_websocket_connection_id(args: list) -> str:
136136

137137

138138
@lru_cache()
139-
def get_websocket_endpoint(endpoint_url: str) -> "ApiGatewayManagementApi": # I can't find this in botocore.client
139+
def get_websocket_endpoint(endpoint_url: str) -> "botocore.client.ApiGatewayManagementApi": # noqa: pyflakes - F821
140140
"""
141141
Gets an instance of ApiGatewayManagementApi for sending messages
142142
through websockets

0 commit comments

Comments
 (0)