-1

I have an AWS Lambda which uses some modules which write to the stdout. These appear in the Lambda logs - however I need to be able to read and parse the stdout after the module is executed within the same lambda.

Is this possible with the Logger library? Note that I would like to read the log from the current execution only.

import os
import logging
logger = logging.getLogger()
logger.setLevel(logging.INFO)

def lambda_handler(event, context):
    # Do Stuff
    log = logger.get_log()# read the log into a variable???
user3437721
  • 2,227
  • 4
  • 31
  • 61

1 Answers1

0

What "AWS Logger Library" are you referring to? The code in your question is using the standard Python logging library, not anything AWS specific. You certainly can't read previous Lambda invocation logs using that library.

You would need to use the AWS SDK for Python (Boto3) to read those logs out of CloudWatch.

You could also configure CloudWatch to stream the log data to another Lambda function.

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • I want to read the current execution lambda log (not any previous execution). – user3437721 Mar 03 '21 at 14:16
  • By default the log is just going to STDOUT so it isn't going to be persisted anywhere inside the Lambda function's context. I if you want to persist it temporarily you would need to configure the logger to write the log to `/tmp` in addition to STDOUT. – Mark B Mar 03 '21 at 14:17