无法让 AWS Lambda 函数记录(文本输出)到 CloudWatch [英] Can't get AWS Lambda function to log (text output) to CloudWatch
问题描述
我正在尝试设置一个 Lambda 函数,该函数将在文件上传到 S3 存储桶时对其进行处理.我需要一种方法来在上传文件时查看 console.log
的输出,但我不知道如何将我的 Lambda 函数链接到 CloudWatch.
I'm trying to set up a Lambda function that will process a file when it's uploaded to an S3 bucket. I need a way to see the output of console.log
when I upload a file, but I can't figure out how to link my Lambda function to CloudWatch.
我通过查看 context
对象发现我的日志组是 /aws/lambda/wavToMp3
并且日志流是 2016/05/23/[$LATEST]hex_code_redacted
.因此,我在 CloudWatch 中创建了该组和流,但没有记录任何内容.
I figured about by looking at the context
object that my log group is /aws/lambda/wavToMp3
and the log stream is 2016/05/23/[$LATEST]hex_code_redacted
. So I created that group and stream in CloudWatch, yet nothing is being logged to it.
推荐答案
为了使 lambda 函数创建日志流并将日志发布到 cloudwatch,lambda 执行角色需要具有以下权限.
For the lambda function to create log stream and publish logs to cloudwatch, the lambda execution role needs to have the following permissions.
{
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Effect": "Allow",
"Resource": "arn:aws:logs:*:*:*"
}
]
}
请参阅以下 AWS 文档了解更多详情http://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html#lambda-intro-execution-role
Please refer to the following AWS documentation for more details http://docs.aws.amazon.com/lambda/latest/dg/intro-permission-model.html#lambda-intro-execution-role
这篇关于无法让 AWS Lambda 函数记录(文本输出)到 CloudWatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!