-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???

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I want to read the current execution lambda log (not any previous execution).
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.