claudiajs / AWS:看不到CloudWatch中的日志,但是代码错误

时间:2017-10-31 15:30:27

标签: node.js aws-lambda amazon-cloudwatch claudiajs

我使用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       在exports.handler(/var/task/lambda.js:7:2)

为什么console.logs没有显示?

1 个答案:

答案 0 :(得分:0)

首先请检查您的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