You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(lambda): deprecate logRetention properties in favor of logGroup (#28737)
#28039 introduced support for custom logging configurations for AWS Lambda Functions.
This change deprecates the `logRetention`, `logRetentionRole` and `logRetentionRetryOptions` properties in favor of using a custom logging configuration.
By default, Lambda functions send logs to an automatically created default log group named `/aws/lambda/<function name>`. However you cannot change the properties of this auto-created log group using the AWS CDK, e.g. you cannot set a different log retention. To overcome the limitation, a custom resource was introduced and configuration exposed via the `logRetention` properties. This is what we are deprecating in this change.
With the introduction of custom logging configuration and the new `logGroup` property, users can now create a fully customizable `LogGroup` ahead of time, and instruct the Lambda function to send logs to it.
Migrating from `logRetention` to `logGroup` will cause the name of the log group to change. Don't attempt to use the name of the auto-created log group, this will cause subtle issue. We recommend using auto-naming for lambda log groups, they can easily be accessed via the Lambda Console. If you want use a well-known name, we recommend using a pattern like `/<your service>/lambda/<function name>`. Be aware that a names log group can prevent a stack from being recreated without manual intervention after it has been deployed (error `Resource already exists`). This is because `LogGroups` are retained by default.
Either way, users will have to adjust and documentation will need to be updated. Any code referencing the old log group name verbatim will have to be changed as well. Keep in mind that in AWS CDK code, you can access the log group name directly from the `LogGroup` construct:
```ts
declare const myLogGroup: logs.LogGroup;
myLogGroup.logGroupName;
```
----
*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Copy file name to clipboardExpand all lines: packages/aws-cdk-lib/aws-lambda/README.md
+18-15Lines changed: 18 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -988,24 +988,28 @@ See [the AWS documentation](https://docs.aws.amazon.com/lambda/latest/dg/invocat
988
988
989
989
## Log Group
990
990
991
-
Lambda functions automatically create a log group with the name `/aws/lambda/<function-name>` upon first execution with
991
+
By default, Lambda functions automatically create a log group with the name `/aws/lambda/<function-name>` upon first execution with
992
992
log data set to never expire.
993
+
This is convenient, but prevents you from changing any of the properties of this auto-created log group using the AWS CDK.
994
+
For example you cannot set log retention or assign a data protection policy.
993
995
994
-
The `logRetention` property can be used to set a different expiration period.
996
+
To fully customize the logging behavior of your Lambda function, create a `logs.LogGroup` ahead of time and use the `logGroup` property to instruct the Lambda function to send logs to it.
997
+
This way you can use the full features set supported by Amazon CloudWatch Logs.
995
998
996
-
It is possible to obtain the function's log group as a `logs.ILogGroup` by calling the `logGroup` property of the
997
-
`Function` construct.
998
-
999
-
By default, CDK uses the AWS SDK retry options when creating a log group. The `logRetentionRetryOptions` property
1000
-
allows you to customize the maximum number of retries and base backoff duration.
999
+
```ts
1000
+
import { LogGroup } from'aws-cdk-lib/aws-logs';
1001
1001
1002
-
*Note* that, if either `logRetention` is set or `logGroup` property is called, a [CloudFormation custom
1003
-
resource](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-cfn-customresource.html) is added
1004
-
to the stack that pre-creates the log group as part of the stack deployment, if it already doesn't exist, and sets the
1005
-
correct log retention period (never expire, by default).
* remove the retention policy, set the value to `INFINITE`.
386
386
*
387
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.
390
+
* Migrating from `logRetention` to `logGroup` will cause the name of the log group to change.
391
+
* Users and code and referencing the name verbatim will have to adjust.\
392
+
* In AWS CDK code, you can access the log group name directly from the LogGroup construct:
0 commit comments