print statements in Greengrass v2 lambda not logged

0

It looks like even the simplest print statements in python 3.7 in Lambda functions for Greengrass v2 do not get logged anywhere. I've checked in /greengrass/v2/logs/<componentName>.log and /greengrass/v2/work/<componentName>/logs/0/ and don't see them. Is there some sort of config I need to add to make print statements go to the log files?

kdixson
asked 2 years ago39 views
9 Answers
0

Hi,
This will be due to Python buffering the output. Please see: https://docs.aws.amazon.com/greengrass/v2/developerguide/troubleshooting.html#python-component-no-log-output.

Cheers,
Michael Dombrowski

answered 2 years ago
0

I suppose not, as the first LoC is print("up and running", flush=True). Is there anywhere else that stdout would be redirected to?

Edited by: kdixson on Apr 26, 2021 6:56 PM

kdixson
answered 2 years ago
0

The output will be in the component's logfile, located at <root>/logs/<component name>.log.

Are you certain that your lambda is actually being run? If it is running is it in container mode? If yes, you may need to increase the memory limit which is only 16MB by default and will often cause the lambda to be killed.

Please provide the code, or a minimal example which replicates the issue.

Cheers,
Michael Dombrowski

answered 2 years ago
0

Here is my code: https://gist.github.com/Lard4/28c86ae0670ef21da911b4520444c7f0

It's curious because if you comment out line 42, the topic will publish successfully, but nothing will get logged. In fact, the log file doesn't even exist in /greengrass/v2/logs.

If you leave 42 uncommented, something happens (I suppose some sort of exception gets thrown) and the lambda doesn't report a status and after 60 seconds, greengrass kills and retries the lambda. No print statements or exceptions get logged in the lambda's log. However, you can see the exception where greengrass gets no timely status report and kills the lambda. (see the greengrass.log here: https://gist.github.com/Lard4/8a7842c1f138243eacfc789033bd2e4c)

kdixson
answered 2 years ago
0

Please remove the file and stream options which are referring to sys.stdout. Just use a normal print or log statement.

Are you running in container mode? As I mentioned before, it is possible that it is running out of memory and being killed.

It is not possible for the component's log file to not exist; the log file is created just as soon as the component is deployed to the system.

Please provide the contents of <root>/configs/effectiveConfig.yaml file.

Cheers,
Michael Dombrowski

answered 2 years ago
0

I've tried it both in a container and not in a container. Both don't log anything. Here is my effectiveConfig.yaml: https://gist.github.com/Lard4/d3d7ef24fdce17dcd3c63686f3b86908

Note that the lambda under investigation is called DataIngestionLambda

Edited by: kdixson on Apr 27, 2021 11:06 AM

kdixson
answered 2 years ago
0

I just removed the sys.stdout from the print statements, and no log file is being created.

kdixson
answered 2 years ago
0

Please attach the entirety of the logs directory to this forum post so that I can review all the logs.

Cheers,
Michael Dombrowski

answered 2 years ago
0

I ended up uninstalling greengrass and reinstalling, this fixed my issues

kdixson
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions