How do I use logger in lambda?

Asked 2 years ago, Updated 2 years ago, 125 views

On lambda, we have prepared the following scripts to verify logger operation:

import logging

deflambda_handler(event, context):
    # print("Received event:" + json.dumps(event,indent=2))"

    logging.basicConfig (level=logging.DEBUG)
    logger = logging.getLogger()
    logger.debug('test')

if__name__=='__main__':
    lambda_handler (None, None)

If you do this from the command line, the log will output correctly as follows:

$python lambda_function.py
DEBUG:root:test

However, if you do this on lambda, the logger does not appear.

Question:

  • How do I debug/info output the logger on lambda?

python aws aws-lambda

2022-09-29 22:29

1 Answers

Is it not recorded in CloudWatch Logs?

Logging (Python)
Accessing AWS Lambda's Amazon CloudWatch Logs


2022-09-29 22:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.