我已经创建了云前端分发并将 lambda 附加到触发器
`Event type: viewer-requestPath pattern: something/index.html`
Event type: origin-requestPath pattern: something/index.html
根据我的 lambda,当我到达端点时,它会重定向到我想要重定向的页面。
但我无法在任何区域看到我的 lambda 日志。
它也没有显示调用计数。
有人遇到过这个问题吗??
这是我的 lambda 代码
'use strict';
exports.handler = (event, context, callback) => {
/*
* Generate HTTP redirect response with 302 status code and Location header.
*/
console.log('event',event);
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'http://<domainname>/something/root.html',
}],
},
};
callback(null, response);
};
最佳答案
像这样修改你的函数:
const response = {
status: '302',
statusDescription: 'Found',
headers: {
location: [{
key: 'Location',
value: 'http://<domainname>/something/root.html',
}],
'x-lae-region': [ { key: 'x-lae-region', value: process.env.AWS_REGION } ],
},
};
它的作用是捕获您的 lambda 函数正在运行的区域——它会在测试期间显示 us-east-1,但在部署后会显示准确的值。
您的浏览器、curl 等捕获的响应现在将包括 x-lae-region: some-aws-region
以指示链接到处理您的特定请求的边缘的区域.检查该特定区域的日志——您应该在那里看到日志和调用。
另请注意,对于源请求(而非查看器请求)触发器,CloudFront 会缓存 Lambda 生成的响应,因此只有在缓存未命中时才会调用该函数。如果 CloudFront 缓存了响应,触发器将不会触发——缓存的响应在不联系源的情况下提供。如果您使此功能生效并且您没有看到响应中的变化,那么您几乎可以肯定正在查看缓存的响应,并且会想要执行无效操作。
关于amazon-web-services - lambda@edge 日志和调用计数没有显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49514290/