简体   繁体   English

为什么我在 CloudWatch 和 lambda function 的控制台中看不到我的日志?

[英]Why I don't see my log in the console at CloudWatch and lambda function?

I have lambda function, but I don't see my log at the console.log in CloudWatch.我有 lambda function,但在 CloudWatch 的 console.log 中看不到我的日志。 what is missing here?这里缺少什么?

'use strict';
exports.handler = (event, context, callback) => {
    
    //Get contents of response
    const response = event.Records[0].cf.response;
    const headers = response.headers;

//Set new headers 
 headers['strict-transport-security'] = [{key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubdomains; preload'}]; 
 headers['content-security-policy'] = [{key: 'Content-Security-Policy', value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'"}]; 
 headers['x-content-type-options'] = [{key: 'X-Content-Type-Options', value: 'nosniff'}]; 
 headers['x-frame-options'] = [{key: 'X-Frame-Options', value: 'DENY'}]; 
 headers['x-xss-protection'] = [{key: 'X-XSS-Protection', value: '1; mode=block'}]; 
 headers['referrer-policy'] = [{key: 'Referrer-Policy', value: 'same-origin'}]; 
 
 console.log('in handler');
 
 console.log({ xx: event.Records[0].cf.request.uri });
    
 console.log('end handler ');
 
    //Return modified response
    callback(null, response);
};

https://console.aws.amazon.com/cloudwatch/home?region=us-east-1 https://console.aws.amazon.com/cloudwatch/home?region=us-east-1 在此处输入图像描述

在此处输入图像描述

CloudWatch:云观察: 在此处输入图像描述

Lambda Test: Lambda 测试:

在此处输入图像描述

From the behaviour you're experiencing I suspect this is simply that a new version of the Lambda@Edge has not been deployed to the CloudFront distribution.根据您遇到的行为,我怀疑这只是新版本的 Lambda@Edge 尚未部署到 CloudFront 分配。

Whenever you need to release an update of the code you must create a new version of the Lambda function and then replace the Lambda event in your CloudFront distribution to use the new version record.每当您需要发布代码更新时,您必须创建 Lambda function 的新版本,然后替换 CloudFront 分发中的 Lambda 事件以使用新版本记录。

Once this happens it will take a short while to modify in every edge location so you might not immediately see these debug lines in your logs.一旦发生这种情况,在每个边缘位置进行修改都需要很短的时间,因此您可能不会立即在日志中看到这些调试行。

As this process takes time to deploy, make sure to make use of the test events (as input to your Lambda) to test the scenarios that need to be tested once the Lambda is deployed.由于此过程需要时间来部署,因此请确保使用测试事件(作为 Lambda 的输入)来测试部署 Lambda 后需要测试的场景。 Once you're happy with it perform the new version and deploy.一旦您对它感到满意,就执行新版本并进行部署。

For more information take a look at the Editing a Lambda Function for Lambda@Edge page.有关更多信息,请查看为 Lambda@Edge 编辑 Lambda Function页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我看不到 Lambda 函数的 CloudWatch 日志? - Why can't I see CloudWatch Logs for Lambda function? 为什么我在CloudWatch中看不到所有SQS队列的指标 - Why I don't see metrics for all SQS queues in CloudWatch 为什么我在 lambda 函数中看不到日志? - Why can't I see logs in my lambda function? 为什么我在 cloudwatch 中看不到 lambda 的打印和日志,重复调用 function? - why cant i see prints and logs from lambda in cloudwatch , the function is invoked repeatedly? 我在我的 AWS lambda 中启用了子流程输出 - 为什么这个日志输出没有被推送到 CloudWatch? - I have enabled subprocess output in my AWS lambda - why is this log output not being pushed to CloudWatch? 如何在多个 AWS Cloudwatch 日志流中查找 Python lambda function 的错误日志? - How do I find error logs for my Python lambda function across many AWS Cloudwatch log streams? 无法让 AWS Lambda 函数记录(文本输出)到 CloudWatch - Can't get AWS Lambda function to log (text output) to CloudWatch 为什么触发了我的 CloudWatch 规则但没有调用我的 Lambda 函数? - Why is my CloudWatch rule triggered but not invoking my Lambda function? 如何在部署的 Lambda function 中查看 console.log 语句 - How to see console.log statements in deployed Lambda function 为什么不能在控制台中创建AWS Lambda函数? - Why can't I create an AWS Lambda function in console?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM