0
votes

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?

1
it should be console not conesole - kgangadhar
Sure. I know. That was the test. If I write "conesole" then a Reference error is displayed in the logs, if I write "console" then nothiong apears. - Michael
Configure a lambda test event for you function from the aws console and attach the output you see in the aws console. - Madhukar Mohanraju

1 Answers

0
votes

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