Logging your comments and errors clearly is always a good software practice. So, we shall now understand how to log from inside of Lambda functions. There are broadly two ways of logging inside Lambda functions. We shall now learn and understand them via examples from the following steps:
- The first way is to use Python's logging library. This is widely used as a standard practice for logging in Python scripts. We shall edit the code we have written previously for the serverless API and add in the logging statements in it. The code will look like this:
The code which is in the preceding screenshot is as follows:
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)
def lambda_handler(event, context):
mobs = {
"Sea": ["GoldFish", "Turtle", "Tortoise", "Dolphin", "Seal"...