aws lambda:如何从真实请求(不是测试)中获取 console.log 日志?
aws lambda: how to get console.log logs from real request (not test)?
我读过这个文档:https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html 并做了这个 lambda:
exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);
//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response
return response;
};
当我将 "test" 与假模型一起使用时,它可以工作(日志发送到 CloudWatch),但是当我添加 CloudFront 触发器并发送请求时,日志不会发送到任何 CloudWatch。
- 如何从 lambda
中获得真实的(从生产中)event
对象
- 如何 send/get 来自 CloudFront 触发的 lambda 的日志?
由于Lambda是由CloudFront触发的,现在变成了Lambda@Edge,所以CloudWatch Log流是在调用Lambda实例的区域创建的(由CloudFront决定)。
所以在 AWS Lambda@Edge Docs for Troubleshooting 之后,可以使用提供的 shell 脚本轻松确定特定区域。
我读过这个文档:https://docs.aws.amazon.com/en_us/lambda/latest/dg/nodejs-prog-model-logging.html 并做了这个 lambda:
exports.handler = async (event) => {
// TODO implement
// const response = {
// statusCode: 200,
// body: JSON.stringify('Hello from Lambda!'),
// };
console.log(123321);
console.log(event.Records[0].cf.response);
console.log(event.Records[0].cf.request);
console.log(JSON.stringify(event.Records[0].cf));
console.log(event);
console.log(arguments);
//Get contents of response
const response = event.Records[0].cf.response;
//Return modified response
return response;
};
当我将 "test" 与假模型一起使用时,它可以工作(日志发送到 CloudWatch),但是当我添加 CloudFront 触发器并发送请求时,日志不会发送到任何 CloudWatch。
- 如何从 lambda 中获得真实的(从生产中)
- 如何 send/get 来自 CloudFront 触发的 lambda 的日志?
event
对象
由于Lambda是由CloudFront触发的,现在变成了Lambda@Edge,所以CloudWatch Log流是在调用Lambda实例的区域创建的(由CloudFront决定)。
所以在 AWS Lambda@Edge Docs for Troubleshooting 之后,可以使用提供的 shell 脚本轻松确定特定区域。