[lambda] expose log group and support metric filter
See original GitHub issue🚀 Feature Request
General Information
- 👋 I may be able to implement this feature request
- ⚠️ This feature might incur a breaking change
Description
Currently it’s impossible to add MetricFilter for Lambda logs, because Lambda does not return log group and log group will be created only after any invocations of function. Manually created log groups (in CDK) might not work because of possible race conditions.
Addition of MetricFilter to logs is similar to LogGroup retention setting as discussed here https://github.com/aws/aws-cdk/issues/667#issuecomment-474002870 and implemented in PR #2067
Proposed Solution
Environment
- CDK CLI Version: all
- Module Version: all
- OS: all
- Language: all
Other information
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Create a metric filter for a log group - Amazon CloudWatch Logs
How to create a metric filter that publishes a metric to CloudWatch based on the ... In the navigation pane, choose Logs, and...
Read more >Ensure a log metric filter and alarm exist for changes to NACLs
Monitoring changes to NACLs will help ensure that AWS resources and services are not unintentionally exposed. We recommend you establish a log metric...
Read more >Sending CloudWatch Custom Metrics From Lambda ... - Stackify
Today's post is a detailed guide on how to send custom metrics to AWS CloudWatch monitoring using AWS Lambda. Starting from scratch, we're ......
Read more >Amazon CloudWatch Logs and AWS Lambda - YouTube
Learn more about AWS at - http://amzn.to/2zdfmIe.In this session, we cover three common scenarios that include Amazon CloudWatch Logs and ...
Read more >Monitoring AWS Lambda Functions With CloudWatch
We will use existing metrics but also create a custom metric filter to parse the memory consumption from CloudWatch logs.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There seems to be two ways to do this:
new logGroup()
LogGroup.fromLogGroupArn()
The first method only works if the log group doesn’t already exist, but the second one only works if the log group already exists. In my scenario I had made the lambda (and the log group) in a previous deploy, and then I wanted to add a subscription to the log group in a second deploy, so I had to use the second variant. But then I tried to deploy this construct in a new stack, and now it failed, since the log group didn’t exist yet. So Unless you know the state of the stack you are deploying to you can’t really use these.
@nija-at I take that back, I can actually create the log group. I’m not sure what I did wrong last time when I received the naming error.
After working through this, it seems that I now have an acceptable flow. In my TS code I simply 1) declare the LogGroup after the lambda.Function and follow the standard naming convention
/aws/lambda/' + this.functionName
. 2) I reference the log group on the MetricFilter by simply usingthis.logGroup
. This order seems to work (e.g. lambda function first, log group second).Problem solved. Thanks! For anyone else struggling with this: