如何在python中禁用来自lambda的默认日志消息 [英] How to disable default log messages from lambda in python
问题描述
我有一个用python编写的AWS Lambda函数,我只需要在CloudWatch Logs中记录的消息。
我已经尝试了watch望塔中给出的示例,但是仍然无法正常工作。
I have an AWS Lambda function written in python, and i need only the messages I log in CloudWatch Logs. I have tried the example given in watchtower, but it still didn't work.
START RequestId: d0ba05dc-8506-11e8-82ab-afe2adba36e5 Version: $LATEST
(randomiser) Hello from Lambda
END RequestId: d0ba05dc-8506-11e8-82ab-afe2adba36e5
REPORT RequestId: d0ba05dc-8506-11e8-82ab-afe2adba36e5
Duration: 0.44 ms Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 21 MB*
从上面我只需要Lambda的(randomiser)Hello
即可登录CloudWatch,而无需 START
, END
和 REPORT
行。
From the above I only need (randomiser) Hello from Lambda
to be logged in CloudWatch, without the START
, END
and REPORT
lines.
推荐答案
如果启用了日志,则总是会获取默认日志。您无法禁用它们。
If you have logs enabled, you are always going to get the default logs. No way you can disable them.
但是,在某些情况下,您可能希望某个特定的Lambda函数完全不发送日志。您可以通过专门为该Lambda函数创建一个新角色来解决此问题,并且在那里没有日志记录权限。
However there might be cases where you want one specific Lambda function to not send logs at all. You can solve this by creating a new role specifically for that Lambda function, and not have the logging permission there.
FWIW,如果需要在日志记录和无日志记录之间切换通常,您可以具有以下策略文件。
FWIW, if you need to toggle between logging and no logging frequently, you can have a policy file as the following.
{
版本: 2012-10 -17,
声明:[
{
效果: Deny,
操作:[
logs:CreateLogGroup,
logs:CreateLogStream,
logs:PutLogEvents
],
资源:[
arn:aws:logs:*:*:*
]
}
]
}
并更改需要记录时,将拒绝更改为允许。
and change the "Deny" to "Allow" when you require logging.
这篇关于如何在python中禁用来自lambda的默认日志消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!