Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(aws-lambda): Allow writing Lambda logs to existing Log Group #8672

Closed
1 of 2 tasks
Dzhuneyt opened this issue Jun 21, 2020 · 7 comments
Closed
1 of 2 tasks

(aws-lambda): Allow writing Lambda logs to existing Log Group #8672

Dzhuneyt opened this issue Jun 21, 2020 · 7 comments
Assignees
Labels
@aws-cdk/aws-lambda Related to AWS Lambda closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. feature-request A feature should be added or improved.

Comments

@Dzhuneyt
Copy link
Contributor

Our project relies heavily on many Lambdas (that back AppSync as Data Sources). We'd love to be able to have a centralized "log" of all these lambdas. Currently, such logs are scattered across multiple Log groups (one per lambda). In other words, the Lambda construct currently creates its own log group and has no way of referring to an existing Log group where Lambda logs should be written.

Proposed Solution

new Function(this, 'fn', {
    code: ...,
    handler: ....,
    logGroup: LogGroup.fromLogGroupArn(...),
})
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@Dzhuneyt Dzhuneyt added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2020
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Jun 21, 2020
@nija-at
Copy link
Contributor

nija-at commented Jun 22, 2020

Unfortunately, the Lambda service reports logs to a specific log group, named after the function - https://docs.aws.amazon.com/lambda/latest/dg/monitoring-cloudwatchlogs.html.

As far as I know, there is no way to control which log group this goes to.

the Lambda construct currently creates its own log group

Not technically. In the default case, the Lambda service creates this log group. When you specify the logRetention property in the CDK, the CDK creates the log group if it doesn't already exist and adjusts its retention policy; however, the log group name must be what Lambda expects it to be.

Let me know if there's something that I missed here.

@nija-at nija-at added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Jun 22, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Jun 22, 2020
@github-actions github-actions bot added closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Jun 27, 2020
@sith
Copy link

sith commented Sep 13, 2021

nija-at, could you explain why this limitation exists.

I have a state machine with multiple lambda functions and I want to have logs in one place rather going and querying them in corresponding lambda log groups.

@Dzhuneyt
Copy link
Contributor Author

@sith this is a limitation of the AWS Lambda service itself, not something that can be solved with CloudFormation or AWS CDK (which all are built on top of AWS services like Lambda). See this for further information.

If you want to achieve true aggregation of logs for your whole State Machine that is composed of Lambdas that write to multiple LogGroups, you can either query across multiple LogGroups using something like the CloudWatch Logs Insights tool or implement your own logging layer inside the application runtime code (so e.g. replace your console.log() lines with Logger.getInstance().log(message))

@lefnire
Copy link

lefnire commented May 26, 2023

I'm looking at cdk-lib/lambda/Function and I see a {logGroup?: ILogGroup} prop:

The LogGroup where the Lambda function's logs are made available.

I'm wondering if maybe this prop became available after this discussion took place? Unless I'm misunderstanding its functionality. If I'm not mistaken, one can just:

import * as logs from '@aws-cdk/aws-logs';
import * as lambda from '@aws-cdk/aws-lambda';

const aggregatedLogGroup = new logs.LogGroup(this, 'AggregatedLogGroup', {
  logGroupName: '/aws/lambda/aggregated',
});

const myFunction = new lambda.Function(this, 'MyFunction', {
  ...
  logGroup: aggregatedLogGroup,
});

@Dzhuneyt
Copy link
Contributor Author

Dzhuneyt commented Jun 7, 2023

@lefnire you are probably mistaking the lambda.logGroup getter function for a prop. The FunctionProps interface (which declares the input configuration for the created lambda) does not accept any logGroup configuration. Only logGroup expiration settings.

@lefnire
Copy link

lefnire commented Jun 8, 2023

@Dzhuneyt you're absolutely correct. Thanks for pointing that out!

@tilak-puli
Copy link

tilak-puli commented Jan 9, 2024

Just an update:

I see a change in CDK API to set a custom log group from v2.110. I am trying to use this and will update after using

https://github.com/aws/aws-cdk/releases/tag/v2.110.0
#28039

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda Related to AWS Lambda closed-for-staleness This issue was automatically closed because it hadn't received any attention in a while. feature-request A feature should be added or improved.
Projects
None yet
Development

No branches or pull requests

6 participants