aws / aws/aws-cdk

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

Open
#30,777 5 comments 2 reactions 0 assignees View on GitHub
@aws-cdk/custom-resources effort/medium feature-request p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
1d 19h
Merged PRs (30d)
71

Description

### 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:

```ts
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

Contributor guide

Open the contributing guide

Research direction

Start by tracing the built-in custom resource providers and the Lambda functions generated behind resources such as eks.Cluster. Compare providers whose LoggingConfig is undefined and determine where a universal or custom configuration could be specified. Done means users can configure LoggingConfig for all applicable generated providers without maintaining custom functions or Aspects.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, typescript
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.