我有lambda函数,但我在CloudWatch的console.log中看不到我的日志。这里缺少什么?
'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


CloudWatch:

Lambda测试:

发布于 2020-08-01 19:57:19
从你所经历的行为来看,我怀疑这仅仅是因为Lambda@Edge的新版本还没有被部署到CloudFront发行版。
每当需要发布代码更新时,都必须创建Lambda函数的新版本,然后替换CloudFront发行版中的Lambda事件以使用新的版本记录。
一旦发生这种情况,它将花费很短的时间在每个边缘位置进行修改,因此您可能不会立即在日志中看到这些调试行。
由于此过程需要时间来部署,因此请确保使用测试事件(作为Lambda的输入)来测试在Lambda部署后需要测试的场景。一旦您对它感到满意,执行新版本并进行部署。
有关更多信息,请查看Editing a Lambda Function for Lambda@Edge页面。
https://stackoverflow.com/questions/63204776
复制相似问题