[英]I have enabled subprocess output in my AWS lambda - why is this log output not being pushed to CloudWatch?
I have a piece of code which is failing and I am trying to debug using AWS Cloudwatch logs.我有一段代码失败,我正在尝试使用 AWS Cloudwatch 日志进行调试。 The piece of code, with logging enabled is as follows:
启用日志记录的代码如下:
def run_command(args, cwd):
try:
proc = subprocess.run(args,
cwd=cwd,
timeout=720,
check=True,
capture_output=True)
stdout = proc.stdout
stderr = proc.stderr
except subprocess.TimeoutExpired as e:
logging.debug(proc.stdout)
print(e.output)
print(e)
I expect the subprocess output to be displayed in my AWS Cloudwatch logs.我希望子流程输出显示在我的 AWS Cloudwatch 日志中。 However, here is the output:
但是,这是输出:
START RequestId: 1234567 Version: $LATEST
Command '['my command']' returned non-zero exit status 1.
END RequestId: 1234567
I am running the function like: run_command('ls',cwd)
.我正在运行这样的函数:
run_command('ls',cwd)
。 I am expecting more information on the second line, as I added the capture_output=True
statement.我期待第二行的更多信息,因为我添加了
capture_output=True
语句。 Why is the output of the subprocess command not being logged to my Cloudwatch group, and is it possible to do this?为什么 subprocess 命令的输出没有记录到我的 Cloudwatch 组中,是否可以这样做?
Thanks谢谢
Do quick test and ensure that your Lambda function has been assigned the AWSLambdaBasicExecutionRole.
进行快速测试并确保您的 Lambda 函数已分配
AWSLambdaBasicExecutionRole.
Also, There's a very good article from this guy named Paul Singman.另外,这个叫保罗辛曼的人写了一篇很好的文章。 He explains why we shouldn't be using the
print
to log.他解释了为什么我们不应该使用
print
来记录。 Check here 在这里查看
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.