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

feat(custom-resource): universal loggingConfig for all custom resource providers #30777

Open
2 tasks
pahud opened this issue Jul 7, 2024 · 2 comments
Open
2 tasks
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2

Comments

@pahud
Copy link
Contributor

pahud commented Jul 7, 2024

Describe the feature

CDK has some built-in custom resources that come with providers with LoggingConfig undefined. This may violate some cooperation compliance requirements.

We need an approach to allow users to specify an universal or custom LoggingConfig for all those lambda providers.

Use Case

To make sure all lambda functions CDK auto generates have LoggingConfig configured with custom retention period.

Proposed Solution

Not sure what would be the best solution but at this moment, users would have to write a custom function or Aspects.

Let's say if we need to ensure all custom resources behind the eks.Cluster has LoggingConfig defined:

export class DummyStack extends Stack {
  readonly globalClusterIdentifier: string;
  private readonly processed: CfnResource[] = [];
  private lambdaSharedLogGroup: logs.ILogGroup;
  constructor(scope: Construct, id: string, props?: StackProps) {
    super(scope, id, props);

    new eks.Cluster(this, 'Cluster', {
      version: eks.KubernetesVersion.V1_30,
    });

    // create a shared log group
    this.lambdaSharedLogGroup = new logs.LogGroup(this, id, {
      retention: logs.RetentionDays.NINE_YEARS,
    });

    this.ensureLambdaLogs();

  }

  private ensureLambdaLogs(construct?: IConstruct[]) {
    // this method ensure log group for each lambda function with custom retention period
    (construct ?? this.node.findAll()).forEach(c => {
      if (CfnResource.isCfnResource(c)) {
        if (c.cfnResourceType === 'AWS::Lambda::Function' && (c as lambda.CfnFunction).loggingConfig === undefined) {
          console.log('got lambda resource with undefined loggingConfig: ' + c.cfnResourceType )
          this.addLoggingConfigOverride(c as lambda.CfnFunction)
        } else {
          console.log('got resource type ' + c.cfnResourceType)
        }
      } else {
         this.ensureLambdaLogs(c.node.children);
      }
    })
  }
  private addLoggingConfigOverride(f: lambda.CfnFunction) {
    f.addPropertyOverride('LoggingConfig', {
      'LogGroup': this.lambdaSharedLogGroup.logGroupName,
    })
  }
} // end stack

Other Information

No response

Acknowledgements

  • I may be able to implement this feature request
  • This feature might incur a breaking change

CDK version used

2.147.0

Environment details (OS name and version, etc.)

all

@pahud pahud added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. p2 labels Jul 7, 2024
@pahud pahud changed the title custom-resource: universal loggingConfig for all custom resource providers feat(custom-resource): universal loggingConfig for all custom resource providers Jul 7, 2024
@pahud
Copy link
Contributor Author

pahud commented Jul 7, 2024

internal tracking: D142944846

@pahud pahud added effort/medium Medium work item – several days of effort @aws-cdk/custom-resources Related to AWS CDK Custom Resources and removed needs-triage This issue or PR still needs to be triaged. labels Jul 7, 2024
@comcalvi
Copy link
Contributor

comcalvi commented Sep 9, 2024

@pahud can you confirm if this feature addresses this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

No branches or pull requests

2 participants