Can't get AWS Lambda function to log (text output) to CloudWatch

后端 未结 15 465
独厮守ぢ
独厮守ぢ 2020-12-13 12:14

I\'m trying to set up a Lambda function that will process a file when it\'s uploaded to an S3 bucket. I need a way to see the output of console.log when I uploa

相关标签:
15条回答
  • 2020-12-13 12:31

    I encountered this problem but none of the answers above solved my issue. It turns out that the region was somehow set to Ohio when I first started CloudWatch. After I changed it to US East (N. Virginia), everything works fine.

    0 讨论(0)
  • 2020-12-13 12:31

    Though this got answered already, Just wanted to add my experience which might be useful for others.

    Even the permissions are set appropriately so that lambda can log in cloudwatch, sometimes it is taking 3-4 hrs to reflect the log groups.

    In my case when using lambda for DynamoDB events, where lambda was given all needed permissions for both cloudwatch and DynamoDB. It took 4 hrs to get the logs reflected. May be some sync issues from AWS end. After 4 hrs without any action from my end, I was able to see the Cloudwatch logs.

    Also make sure that you are seacrching the logs in the same region where your function is created.

    0 讨论(0)
  • 2020-12-13 12:32

    It might already log, we just couldn't find the logs we expect...

    e.g.

    app.use(function simpleLogger (req, res, next) {
      console.info('[Logger]', req.method, req.originalUrl)
      next()
    })
    

    After performing GET /hello?world=1,

    Local console: (simple and clear, nice!)

    [Logger] GET /hello?world=1
    

    CloudWatch Logs: (can you easily find the exact log below?)

    START RequestId: a3552c34-f7a6-11e8-90ba-2fb886f31fb0 Version: $LATEST
    2018-12-04T09:26:11.236Z  a3552c34-f7a6-11e8-90ba-2fb886f31fb0  [Logger] GET /hello?world=1
    END RequestId: a3552c34-f7a6-11e8-90ba-2fb886f31fb0
    REPORT RequestId: a3552c34-f7a6-11e8-90ba-2fb886f31fb0  Duration: 41.02 ms  Billed Duration: 100 ms Memory Size: 128 MB Max Memory Used: 29 MB
    

    Conclusion: too verbose to locate the original logs.

    0 讨论(0)
  • 2020-12-13 12:33

    You might want add the Last Ingestion Time column to the log output. It's taking a few minutes for all my events to be written.

    0 讨论(0)
  • 2020-12-13 12:35

    For the issue was I was trying to create a log group in the Cloudformation script by : AWS::Logs::LogGroup and then trying to push the Lambda log to this log group. :P Novice After careful reading , i found that Lambda creates its own log with the aforementioned format: /aws/lambda/ We just need to provide policy permission to this log group , or just a generic permission with resource as: arn:aws:logs:::*

    hope this helps

    0 讨论(0)
  • 2020-12-13 12:36

    For the lambda function to create log stream and publish logs to cloudwatch, the lambda execution role needs to have the following permissions

    I already had these permissions yet it did not work.

    Just change your timeout by a second and click on 'save and test' button, and you will start to see logs in Cloudwatch.

    I changed the timeout, saved and logs still did not work.

    I assigned another role and logs still did not work.

    What ended up working for me was clicking "Create a custom role", then "Allow". This was it and logs started being generated but since I did not want to use a new role but my existing role, I simply assigned my existing role afterwards and it worked. So technically I should have returned back to original configuration that did not work but now it works. Go figure.

    0 讨论(0)
提交回复
热议问题