Professional Lambda Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the same way you return a
status
of "success" in the happy path scenario, should you return some otherstatus
value when you catch an exception?