[英]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
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.