重新创建/重新附加 AWS Lambda 控制台日志记录到 CloudWatch
我以为我想清除旧日志,结果错误地删除了 CloudWatch 上 Lambda 的“日志流”。
结果,正如我醒着时应该预料到的那样,现在 CloudWatch 根本无法获取 Lambda 的控制台日志。哎呀。
日志组仍然存在。 我可以看到如何创建新的日志流。
我在网上找不到的是让现有 Lambda 输出到这个新流的明确说明……即修复我所做的事情。
有人可以提供说明或指示吗?我确信我不是唯一一个犯过这个错误的人,所以我认为这是一个值得立即使用的答案。
更新:决定尝试通过创建一个全新的 Lambda 进行恢复,运行相同的代码并以相同的方式配置,期望它能正常工作;我的理解是,新的 Lambda 会自动绑定到 CloudWatch 组。
然后我运行测试,单击扭转箭头查看输出的末尾,然后单击“单击此处查看相应的 CloudWatch 日志组。”。它打开 Cloudwatch 查看预期的日志组名称 - 并显示一个大红色警告,表明该组不存在。单击测试输出顶部的“(日志)”会产生相同的行为。
我尝试手动创建组,但现在我又回到原来的位置——lambda 运行,我得到本地日志输出,但日志未到达 CloudWatch。
所以看起来似乎存在更深层次的错误。 CloudWatch 仍在从关键 lambda(驱动我新发布的 Alexa 技能的那个)获取日志,而不太关键的 lambda(技能数据库的计划更新)运行正常,所以我不现在绝对需要它的日志 - 但我需要弄清楚这一点,以便在后台任务中断时我可以读取它们。
由于现在这看起来像是真正的意外行为而不是用户错误,因此我会将其带到 AWS 论坛,如果他们找到答案,我会将其发布到此处。在该系统上,问题现在位于 https://repost.aws/questions/QUDzF2c_m0TPCwl3Ufa527Wg/lambda-logging-to-cloud-watch-seems-to-be-broken
程序员的口头禅:“如果很容易,他们就不需要我们...”
Thinking that I wanted to clear out old logs, I made the mistake of deleting my Lambda's "Log Stream" on CloudWatch.
The result, as I should have expected if I was awake, is that now CloudWatch isn't getting the Lambda's console logs at all. Oops.
The log group still exists.
I can see how to create a new log stream.
What I haven't been able to find on the web is clear instructions to get the existing Lambda to output to this new stream... ie, to repair what I did.
Can someone provide instructions or a pointer to them, please? I'm sure I'm not the only one who's made this mistake, so I think it's an answer worth having on tap.
UPDATE: Decided to try recovering by creating an entirely new Lambda, running the same code and configured the same way, expecting that it would Just Work; my understanding was that a new Lambda binds to a CloudWatch group automagically.
Then I ran my test, clicked the twist-arrow to see the end of the output, and hit "Click here to view the corresponding CloudWatch log group.". It opened Cloudwatch looking at the expected log group name -- with a big red warning that this group did not exist. Clicking "(Logs)" at the top of the test output gave the same behavior.
I tried creating the group manually, but now I'm back where I was -- lambda runs, I get local log output, but the logs are not reaching CloudWatch.
So it looks like there's something deeper wrong. CloudWatch is still getting logs from the critical lambda (the one driving my newly-released Alexa skill), and the less-critical one (scheduled update for the skill's database) is running OK so I don't absolutely need its logs right now -- but I need to figure this out so I can read them if that background task ever breaks.
Since this is now looking like real Unexpected Behavior rather than user error, I'll take it to the AWS forums and post here if they come up with an answer. On that system, the question is now at https://repost.aws/questions/QUDzF2c_m0TPCwl3Ufa527Wg/lambda-logging-to-cloud-watch-seems-to-be-broken
Programmer's mantra: "If it was easy, they wouldn't need us..."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行 Lambda 函数后,您可以转到监控选项卡并单击在 CloudWatch 中查看日志 - 它会将您带到日志应存在的位置。
如果您知道该函数已执行但没有显示日志,请确认您的 Lambda 函数已将
AWSLambdaBasicExecutionRole
分配给 Lambda 函数所使用的 IAM 角色。这将授予 Lambda 函数写入 CloudWatch Logs 的权限。请参阅:AWS Lambda 执行角色 - AWS Lambda< /a>
After a Lambda function is executed, you can go to the Monitoring tab and click View logs in CloudWatch -- it will take you to the location where the logs should be present.
If you know that the function has executed but no logs are appearing, then confirm that your Lambda function has the
AWSLambdaBasicExecutionRole
assigned to the IAM Role being used by the Lambda function. This grants permission for the Lambda function to write to CloudWatch Logs.See: AWS Lambda execution role - AWS Lambda