Skip to content

Commit f89a7d2

Browse files
authored
fix: revert deprecation of logRetention properties (#28934)
### Issue Closes #28919 ### Reason for this change In #28737 and #28783 we have deprecated various `logRetention` properties in favor of the new Logging Configuration feature for Lambda Functions. This new feature provides full control over the Lambda Function log group via the `logGroup` property. However Logging Configuration is not available yet for all regions. Particularly GovCloud and CN regions (at the time this issue was created). For customers in of these regions there is currently no clear migration path. We therefore revert the deprecation of previously deprecated properties. ### Description of changes Revert the deprecation of previously deprecated `logRetention` properties. Update documentation to be more explicit about the various options customers have. ### Description of how you validated changes Documentation & annotation change only. This is a partial revert of the PRs linked about, with minor documentation updates. ### 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) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent d973615 commit f89a7d2

File tree

5 files changed

+53
-10
lines changed

5 files changed

+53
-10
lines changed

packages/aws-cdk-lib/aws-lambda/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,25 @@ new lambda.Function(this, 'Lambda', {
10111011
});
10121012
```
10131013

1014+
Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
1015+
If you are deploying to another type of region, please check regional availability first.
1016+
1017+
### Legacy Log Retention
1018+
1019+
As an alternative to providing a custom, user controlled log group, the legacy `logRetention` property can be used to set a different expiration period.
1020+
This feature uses a Custom Resource to change the log retention of the automatically created log group.
1021+
1022+
By default, CDK uses the AWS SDK retry options when creating a log group. The `logRetentionRetryOptions` property
1023+
allows you to customize the maximum number of retries and base backoff duration.
1024+
1025+
*Note* that a [CloudFormation custom
1026+
resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html) is added
1027+
to the stack that pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the
1028+
correct log retention period (never expire, by default). This Custom Resource will also create a log group to log events of the custom resource. The log retention period for this addtional log group is hard-coded to 1 day.
1029+
1030+
*Further note* that, if the log group already exists and the `logRetention` is not set, the custom resource will reset
1031+
the log retention to never expire even if it was configured with a different value.
1032+
10141033
## FileSystem Access
10151034

10161035
You can configure a function to mount an Amazon Elastic File System (Amazon EFS) to a

packages/aws-cdk-lib/aws-lambda/lib/function.ts

+16-7
Original file line numberDiff line numberDiff line change
@@ -384,37 +384,43 @@ export interface FunctionOptions extends EventInvokeConfigOptions {
384384
* this property, unsetting it doesn't remove the log retention policy. To
385385
* remove the retention policy, set the value to `INFINITE`.
386386
*
387-
* @default logs.RetentionDays.INFINITE
388-
*
389-
* @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.
387+
* This is a legacy API and we strongly recommend you move away from it if you can.
388+
* Instead create a fully customizable log group with `logs.LogGroup` and use the `logGroup` property
389+
* to instruct the Lambda function to send logs to it.
390390
* Migrating from `logRetention` to `logGroup` will cause the name of the log group to change.
391391
* Users and code and referencing the name verbatim will have to adjust.
392392
*
393393
* In AWS CDK code, you can access the log group name directly from the LogGroup construct:
394394
* ```ts
395+
* import * as logs from 'aws-cdk-lib/aws-logs';
396+
*
395397
* declare const myLogGroup: logs.LogGroup;
396398
* myLogGroup.logGroupName;
397399
* ```
400+
*
401+
* @default logs.RetentionDays.INFINITE
398402
*/
399403
readonly logRetention?: logs.RetentionDays;
400404

401405
/**
402406
* The IAM role for the Lambda function associated with the custom resource
403407
* that sets the retention policy.
404408
*
405-
* @default - A new role is created.
409+
* This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
410+
* `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
406411
*
407-
* @deprecated instead use `logGroup` to create a fully customizable log group and instruct the Lambda function to send logs to it.
412+
* @default - A new role is created.
408413
*/
409414
readonly logRetentionRole?: iam.IRole;
410415

411416
/**
412417
* When log retention is specified, a custom resource attempts to create the CloudWatch log group.
413418
* These options control the retry policy when interacting with CloudWatch APIs.
414419
*
415-
* @default - Default AWS SDK retry options.
420+
* This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
421+
* `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
416422
*
417-
* @deprecated instead use `logGroup` to create a fully customizable log group and instruct the Lambda function to send logs to it.
423+
* @default - Default AWS SDK retry options.
418424
*/
419425
readonly logRetentionRetryOptions?: LogRetentionRetryOptions;
420426

@@ -482,6 +488,9 @@ export interface FunctionOptions extends EventInvokeConfigOptions {
482488
*
483489
* Use the `logGroup` property to create a fully customizable LogGroup ahead of time, and instruct the Lambda function to send logs to it.
484490
*
491+
* Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
492+
* If you are deploying to another type of region, please check regional availability first.
493+
*
485494
* @default `/aws/lambda/${this.functionName}` - default log group created by Lambda
486495
*/
487496
readonly logGroup?: logs.ILogGroup;

packages/aws-cdk-lib/aws-s3-deployment/lib/bucket-deployment.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ export interface BucketDeploymentProps {
111111
/**
112112
* The number of days that the lambda function's log events are kept in CloudWatch Logs.
113113
*
114+
* This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
115+
* `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
116+
*
114117
* @default logs.RetentionDays.INFINITE
115-
* @deprecated Use logGroup for full control over the custom resource log group
116118
*/
117119
readonly logRetention?: logs.RetentionDays;
118120

119121
/**
120122
* The Log Group used for logging of events emitted by the custom resource's lambda function.
121123
*
124+
* Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
125+
* If you are deploying to another type of region, please check regional availability first.
126+
*
122127
* @default - a default log group created by AWS Lambda
123128
*/
124129
readonly logGroup?: logs.ILogGroup;

packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,19 @@ export interface AwsCustomResourceProps {
329329
* The number of days log events of the singleton Lambda function implementing
330330
* this custom resource are kept in CloudWatch Logs.
331331
*
332+
* This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
333+
* `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
334+
*
332335
* @default logs.RetentionDays.INFINITE
333-
* @deprecated Use logGroup for full control over the custom resource log group
334336
*/
335337
readonly logRetention?: logs.RetentionDays;
336338

337339
/**
338340
* The Log Group used for logging of events emitted by the custom resource's lambda function.
339341
*
342+
* Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
343+
* If you are deploying to another type of region, please check regional availability first.
344+
*
340345
* @default - a default log group created by AWS Lambda
341346
*/
342347
readonly logGroup?: logs.ILogGroup;

packages/aws-cdk-lib/custom-resources/lib/provider-framework/provider.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,19 @@ export interface ProviderProps {
7070
* updating this property, unsetting it doesn't remove the log retention policy.
7171
* To remove the retention policy, set the value to `INFINITE`.
7272
*
73+
* This is a legacy API and we strongly recommend you migrate to `logGroup` if you can.
74+
* `logGroup` allows you to create a fully customizable log group and instruct the Lambda function to send logs to it.
75+
*
7376
* @default logs.RetentionDays.INFINITE
74-
* @deprecated Use logGroup for full control over the custom resource log group
7577
*/
7678
readonly logRetention?: logs.RetentionDays;
7779

7880
/**
7981
* The Log Group used for logging of events emitted by the custom resource's lambda function.
8082
*
83+
* Providing a user-controlled log group was rolled out to commercial regions on 2023-11-16.
84+
* If you are deploying to another type of region, please check regional availability first.
85+
*
8186
* @default - a default log group created by AWS Lambda
8287
*/
8388
readonly logGroup?: logs.ILogGroup;

0 commit comments

Comments
 (0)