question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: event.cloudwatchLog.logGroup.replace is not a function

See original GitHub issue

This is a (Bug Report Proposal)

Description

For bug reports:

  • What went wrong?

Get the error when reference a log group.

TypeError: event.cloudwatchLog.logGroup.replace is not a function
  • What did you expect should have happened?

replace the reference log group name with real one.

  • What was the config you used?
functions:
  pushCustomAccesslogs:
    handler: logs/logs.handler
    events:
      - cloudwatchLog:
          logGroup: { "Ref": "CustomAccessLogs" }

resources:
  Resources:
    CustomAccessLogs:
      Type: AWS::Logs::LogGroup

  • What stacktrace or error message from your provider did you see?
Serverless: Invoke aws:common:cleanupTempDir
Serverless: Packaging service...
Serverless: Excluding development dependencies...
LogGroupName:  { Ref: 'CustomAccessLogs' }      # <=== Here is the name

  Type Error ---------------------------------------------

  event.cloudwatchLog.logGroup.replace is not a function

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Stack Trace --------------------------------------------

TypeError: event.cloudwatchLog.logGroup.replace is not a function
    at functionObj.events.forEach.event (/usr/lib/node_modules/serverless/lib/plugins/aws/package/compile/events/cloudWatchLog/index.js:48:59)

The error line is:

           LogGroupName = event.cloudwatchLog.logGroup.replace(/\r?\n/g, '');

https://github.com/serverless/serverless/blob/c345e9a9bfb5dd49a13788009430e24c400243f2/lib/plugins/aws/package/compile/events/cloudWatchLog/index.js#L48

Additional Data

Your Environment Information ----------------------------- OS: linux Node Version: 6.11.3 Serverless Version: 1.25.0

I added a debug line before replace function:

          console.log("LogGroupName: " , event.cloudwatchLog.logGroup);

from deploy debug log, seems the logGroup name is not referenced properly:

LogGroupName:  { Ref: 'CustomAccessLogs' }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
medikoocommented, Dec 3, 2021

I’m closing as it’s not really a bug. It’s just we do not support CF intrinsic functions at logGroup property, as to properly handle the event we need to have log group name resolved.

This issue was kept open initially as we didn’t have proper error reporting in place, but now that’s solved with configuration validation backed by schema, and schema clearly indicates we accept an only plain string as an input.

If you feel we can maintain the same functionality while extending the support for CF intrinsic functions at logGroup property, please open a new feature request, detailing the idea. If it’ll promise desired results we will definitely welcome the PR.

1reaction
ghostcommented, Feb 6, 2021

Running in this issue too, whereby we are deploying into multiple accounts and want to dynamically replace the region and account

read-cloudwatch:
  handler: build/read-cloudwatch.handler
  timeout: 30
  events:
      - cloudwatchLog:  
        - Fn::Sub:
          - sns/${AWS::Region}/${AWS::AccountId}/DirectPublishToPhoneNumber
Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to log whenever certain api's are called
Set a Cloudwatch log group and enable events in a lambda function to ... TypeError: event.cloudwatchLog.logGroup.replace is not a function.
Read more >
serverless/serverless - Gitter
I have this serverless example that sends logs (from /aws/lambda/somelogs loggroup) to a lambda. But now I want to send the cloudwatch logs...
Read more >
CloudWatch Logs - LogGroup - AWS Documentation
No information is available for this page.
Read more >
How do I fix "Log group does not exist" errors for Lambda ...
How do I fix " Log group does not exist" errors for Lambda function logs in the CloudWatch console?
Read more >
Top 10 Serverless Deployment Errors (and How to Fix Them)
config file in your function directory. 7. CloudFormation cannot update a stack with custom-named resource request. The error: Failed To Deploy ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found