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

custom-resources: Custom Resources Provider using deprecated logRetention property #28931

Closed
juinquok opened this issue Jan 31, 2024 · 3 comments
Labels
@aws-cdk/custom-resources Related to AWS CDK Custom Resources bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@juinquok
Copy link
Contributor

Describe the bug

Using a Custom Resource as defined using the Provider constructor is resulting in a synthesis warning:

[WARNING] aws-cdk-lib.aws_lambda.FunctionOptions#logRetention is deprecated.
  instead create a fully customizable log group with `logs.LogGroup` and use the `logGroup` property to instruct the Lambda function to send logs to it.
Migrating from `logRetention` to `logGroup` will cause the name of the log group to change.
Users and code and referencing the name verbatim will have to adjust.

In AWS CDK code, you can access the log group name directly from the LogGroup construct:
```ts
declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;

This API will be removed in the next major release.


### Expected Behavior

Synthesis of the Provider class should not throw this error as the underlying code base removes the use of this deprecated option.

### Current Behavior

Using a Custom Resource as created using `Provider` results in a synthesis warning. 

### Reproduction Steps

Instantiate and use a `Provider` in your code similar to this:

new cr.Provider(this, 'someProvider', {
onEventHandler: new lambda.NodejsFunction(this, 'someLambda', {
entry: resolve(__dirname, './myLambda.ts'),
runtime: Runtime.NODEJS_18_X,
handler: 'handler',
timeout: Duration.minutes(10),
logGroup, // Existing log group created outside of this Provider
initialPolicy: [
new iam.PolicyStatement({
resources: [logGroup.logGroupArn],
actions: ['logs:CreateLogStream', 'logs:PutLogEvents'],
}),
],
bundling: {
minify: true,
},
}),
logRetention: RetentionDays.FIVE_DAYS, // This line causes the error
});


### Possible Solution

Inside the `aws-cdk-lib/custom-resources` package, the `Provider` class uses 

new AwsCustomResourceSingletonFunction(this, 'Provider', {
uuid: AwsCustomResource.PROVIDER_FUNCTION_UUID,
lambdaPurpose: 'AWS',
timeout: props.timeout || cdk.Duration.minutes(2),
role: props.role,
logRetention: props.logRetention,
functionName: props.functionName,
vpc: props.vpc,
vpcSubnets: props.vpcSubnets,
});

In the class above, we just need to create the logGroup with defaults if it was not already passed in by the user

Doing that will result in the correct params being passed into the class below which extends the underlying Lambda class which is throwing the syntheses error. 

export class AwsCustomResourceSingletonFunction extends lambda.SingletonFunction {
public constructor(scope: Construct, id: string, props: AwsCustomResourceSingletonFunctionProps) {
super(scope, id, {
...props,
"code": lambda.Code.fromAsset(path.join(__dirname, 'aws-custom-resource-handler')),
"handler": "index.handler",
"runtime": lambda.Runtime.NODEJS_18_X
});
}
}


I can raise a PR to help change this ahead of the deprecation of the field. 

### Additional Information/Context

_No response_

### CDK CLI Version

2.122.0 (build 7e77e02)

### Framework Version

_No response_

### Node.js Version

v18.17.0

### OS

Mac Sonoma v14.3

### Language

TypeScript

### Language Version

_No response_

### Other information

_No response_
@juinquok juinquok added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 31, 2024
@github-actions github-actions bot added the @aws-cdk/custom-resources Related to AWS CDK Custom Resources label Jan 31, 2024
@mrgrain
Copy link
Contributor

mrgrain commented Jan 31, 2024

@mrgrain mrgrain closed this as completed Jan 31, 2024
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.

@mrgrain
Copy link
Contributor

mrgrain commented Jan 31, 2024

Also the deprecation is about the be reverted: #28737

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 bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

2 participants