claudiajs / AWS:无法在 CloudWatch 中看到日志,但代码错误

claudiajs / AWS: Can't see logs in CloudWatch, but code errors

我使用 claudia.js 创建了一个带有 API-网关的 lambda 函数。现在我需要日志。 Cloudwatch 有效,它向我显示带有完整堆栈信息的代码错误。但是当我使用 console.log() 时,我没有输入。

'use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)

exports.handler = (event, context) => {
    console.log(4, "Hello World!")
    awsServerlessExpress.proxy(server, event, context)
}

-> cloudwatch 中没有输出。

'

use strict'
const awsServerlessExpress = require('aws-serverless-express')
const app = require('./app')
const server = awsServerlessExpress.createServer(app)

exports.handler = (event, context) => {
    conesole.log("Hello World!")
    awsServerlessExpress.proxy(server, event, context)
}

cloudwatch 中的输出:

ReferenceError: conesole is not defined at exports.handler (/var/task/lambda.js:7:2)

为什么 console.log 没有显示?

首先请检查您的 Lambda 函数是否有权将日志写入 CloudWatch,否则请附上正确的策略以允许将日志写入云观察。请在下面找到一个具有写入日志权限的示例策略,

{
"Sid" : "YOURSID",
"Effect": "Allow",
"Action": [
"logs:*"
],
"Resource": [
"arn:aws:logs:::*"
]
} 

请参考http://docs.aws.amazon.com/lambda/latest/dg/console-specific-permissions.html#console-permissions-cloudwatch-logs