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

(cdk cli): cdk watch with custom log groups do not stream logs to the terminal #29448

Closed
onhate opened this issue Mar 11, 2024 · 2 comments · Fixed by #29451 · May be fixed by NOUIY/aws-solutions-constructs#98, NOUIY/aws-solutions-constructs#99 or NOUIY/aws-solutions-constructs#101
Labels
@aws-cdk/core Related to core CDK functionality bug This issue is a bug. cli Issues related to the CDK CLI p1 package/tools Related to AWS CDK Tools or CLI

Comments

@onhate
Copy link
Contributor

onhate commented Mar 11, 2024

Describe the bug

After the release of Advanced Logging Controls for Lambda (see https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/) I've decided to move all the logs of my multi-stack deployment to a single unified Log Group per deployed tenant.

It goes likes this:

  • The main stack creates the LogGroup like /aws/lambda/{tenant};
  • The secondary stacks refers to the LogGroup using LogGroup.fromLogGroupArn(...);

Then I discovered that running cdk watch on the main stack I can see the cloudwatch logs on my terminal while on the secondary stacks it does not;

I found at that the cloudwatch log group resolver for the logs basically just assumes the log group is /aws/lambda/{physicalId}

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/api/logs/find-cloudwatch-logs.ts#L114

Expected Behavior

I expect the logs to the displayed on terminal for lambda functions using pre-existing CloudWatch Log Groups not created in the stack (referred by LogGroup.fromLogGroupArn)

Current Behavior

I don't see the logs.

Reproduction Steps

Create a stack that creates a log group;

new LogGroup(this, 'tenant-log-group', {
        logGroupName: `/aws/lambda/xxx`
});

On a secondary stack create a Lambda Function that uses the logGroup referred by LogGroup.fromLogGroupArn instead of creating the log group in the stack itself;

Possible Solution

Check the LoggingConfig.LogGroupName property of the lambda to resolve the CloudWatch Log Group of the Lambda

Additional Information/Context

No response

CDK CLI Version

2.131.0 (build 92b912d)

Framework Version

No response

Node.js Version

20

OS

MacOS

Language

TypeScript

Language Version

No response

Other information

No response

@pahud
Copy link
Contributor

pahud commented Mar 12, 2024

Thank you for the pull request.

@pahud pahud added p1 @aws-cdk/core Related to core CDK functionality and removed needs-triage This issue or PR still needs to be triaged. labels Mar 12, 2024
@mergify mergify bot closed this as completed in #29451 Mar 27, 2024
mergify bot pushed a commit that referenced this issue Mar 27, 2024
… stream logs to the terminal (#29451)

### Issue

Closes #29448

### Reason for this change

After the release of Advanced Logging Controls for Lambda (see https://aws.amazon.com/blogs/compute/introducing-advanced-logging-controls-for-aws-lambda-functions/) I've decided to move all the logs of my multi-stack deployment to a single unified Log Group per deployed tenant.

It goes likes this:

The main stack creates the LogGroup like `/aws/lambda/{tenant}`;
The secondary stacks refers to the LogGroup using  `LogGroup.fromLogGroupArn(...)`;
Then I discovered that running cdk watch on the main stack I can see the cloudwatch logs on my terminal while on the secondary stacks it does not;

I found at that the cloudwatch log group resolver for the logs basically just assumes the log group is `/aws/lambda/{physicalId}`

https://github.com/aws/aws-cdk/blob/main/packages/aws-cdk/lib/api/logs/find-cloudwatch-logs.ts#L114

### Description of changes

Use the Template JSON to resolve the `LoggingConfig.LogGroupName` of the Lambda Function;

### Description of how you validated changes

I've replace the node_modules/aws-cdk of my project with the one built from this PR and I was able to see the logs of my lambda that has custom LogConfig, as you can see it is grabbing the logs of `/aws/lambda/dev` cloudwatch logs

![2024-03-13T10-46-48](https://github.com/aws/aws-cdk/assets/980905/d12113f6-67b6-4a54-96cf-66df6138d7f7)

### Checklist
- [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment