Skip to content

Instantly share code, notes, and snippets.

@peacing
Last active January 4, 2021 00:35
Embed
What would you like to do?
Professional Lambda Function
import sys
import logging
import traceback
import json
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
'''Simple Lambda function.'''
try:
logger.info(f'event: {event}')
artist = event['artist']
logger.info(f'The artist is: {artist}')
return {"status": "success", "message": None}
except Exception as exp:
exception_type, exception_value, exception_traceback = sys.exc_info()
traceback_string = traceback.format_exception(exception_type, exception_value, exception_traceback)
err_msg = json.dumps({
"errorType": exception_type.__name__,
"errorMessage": str(exception_value),
"stackTrace": traceback_string
})
logger.error(err_msg)
@ToddBradley
Copy link

In the same way you return a status of "success" in the happy path scenario, should you return some other status value when you catch an exception?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment