Search code examples
node.jsaws-lambdaamazon-cloudwatchclaudiajs

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


I created a lambda function with an API-Gateway using claudia.js. Now I need logs. Cloudwatch works, it shows me code errors with full stack information. But when I use console.log() I get no entry.

'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)
}

-> No output in 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)
}

Output in cloudwatch:

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

Why are console.logs not shown?


Solution

  • First of all please check your Lambda function is authorized to write log to CloudWatch else please attach correct policy which gives permission to write logs to cloud watch. Please find a sample policy below which has permission to write logs,

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

    Please refer http://docs.aws.amazon.com/lambda/latest/dg/console-specific-permissions.html#console-permissions-cloudwatch-logs