Problem with cloudwatch logs

Hi
I used a lot of console.log in my js app but I can’t see it on cloudwatch. No log is present
here’s my config:

functions:
app:
handler: index.handler
events:
- http:
path: /
method: get
- cloudwatchLog:
logGroup: ‘/aws/lambda/a’
filter: ‘appFilter’
resources:
Resources:
AuthAccessLogs:
Type: AWS::Logs::LogGroup
Properties:
LogGroupName: ‘/aws/lambda/a’

The cloudwatchLog property is monitoring EVENTS from /aws/lambda/a, not writing to it. When something gets written to that log, anything that matches appFilter should get sent in as an event to this function.

console.log statements write to the the default log group created by Serverless. This is in the form of /aws/lambda/your-function-name.

Thank u for your answer
I don’t use EVENTS so I removed the all resources and cloudwatchLog
I uploaded again my functions but I still continue to don’t see any logs in cloudwatch, no stream log, nothing

Have you tried executing your function from the Lambda dashboard? That will show you want you are logging and will link you directly to the correct CloudWatch log group.

The log groups should be visible immediately after deployment. The log streams won’t be visible until after your Lambda has executed.

  1. Go to CloudWatch in the AWS Console then Logs. If you don’t see the log groups then check you’re looking in the same region you deployed your Lambda to.
  2. If you are certain you’re in the right region then go to Lambda in the AWS Console. Click on one of the Lambda you have executed recently. Go to the Monitoring tab and confirm the Lambda was executed. If your Lambda hasn’t been executed then you need to figure that out first. Click on Jump to Logs to see log entries. You might not see log entries (sometimes it happens when viewing all streams) but if you go back to the log group using the breadcrumbs you will see all of the log streams. Clicking on the most recent log stream will show you the entries.

If everything else fails - is it possible you deleted the log groups manually? Try completely removing the project using sls remove then deploying using sls deploy. Repeat the checks.

1 Like

I think maybe I’ve another type of problem:
now my serverless.yml is so simple:

functions:
    auth:
        handler: index.auth
        cors: true
    app:
        handler: index.handler
        events:
            - http: 
                path: /
                method: get
                authorizer: auth
                cors: true
            - http: 
                path: asd
                method: get
                authorizer: auth
                cors: true

and my auth function is:

exports.auth = (event, context, callback) => {
s.auth = (event, context, callback) => {
console.log("abc")
return callback('Unauthorized - no access token')
}

I cannot see the log but also in graphics I don’t see execution time and execution count, still 0!
when I’ll try to access at my lambda from the url continue to say:
{"message":"Unauthorized"}

The cors: true on the auth handler won’t do anything.

Are you using Node 6.19 or 8.10?

Also, can you try triggering the Lambda from the console?

i’m using 8.10 and i’ll tried also to remove cors:true, no changes

how can I try to trigger lambda from the console?

Log in to the AWS Console and go to the Lambda service console. Then click on the function you want to test. This will open up the details of the function. At the top there is an option to “TEST” the function. Click test and then create a sample event. You can use the default or select a preconfigured one from the drop down. Save it, and then click “TEST” again. It will run the function and show you the output and logs with a link to the CloudWatch log group.

perfect!
yes if I’ll try to test it on lambda console it works, the log appear and the right message appear too!

Why my auth function doesn’t executed when I call my url endpoint? what’s wrong?

It sounds like you’re using the wrong URL for the endpoint.

Also, it should be

return callback(new Error('Unauthorized - no access token'));

I’m currently using the URLs given by serverless deploy console

endpoints:
GET - https:/blablabla.execute-api.eu-west-1.amazonaws.com/staging/