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
已提問 3 年前檢視次數 362 次
9 個答案
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

AWS
專家
已回答 3 年前
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
已回答 3 年前
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

AWS
專家
已回答 3 年前
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
已回答 3 年前
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

AWS
專家
已回答 3 年前
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
已回答 3 年前
0

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

kdixson
已回答 3 年前
0

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

Cheers,
Michael Dombrowski

AWS
專家
已回答 3 年前
0

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

kdixson
已回答 3 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南