Skip to content

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

@onhate

Description

@onhate

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.cliIssues related to the CDK CLIp1package/toolsRelated to AWS CDK Tools or CLI

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions