-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Make log groups for Lambda/CodeBuild accessible and/or manipulable #667
Make log groups for Lambda/CodeBuild accessible and/or manipulable #667
Comments
Would be better if we can do this in CloudFormation, but we currently cannot. There are two issues if we were to create a LogGroup object as part of the deployment, as in this example: class LoggedFunction extends lambda.Function {
constructor(scope: cdk.Construct, id: string, props: lambda.FunctionProps) {
super(scope, id, props);
const log = new logs.LogGroup(this, `${id}-LogGroup`, {
retentionDays: 30,
logGroupName: `/aws/lambda/${this.functionName}`,
});
const logResource = log.node.findChild('Resource') as logs.CfnLogGroup;
logResource.options.deletionPolicy = cdk.DeletionPolicy.Delete;
}
}
|
Adds a new property `logRetentionDays` on `Function` to control the log retention policy of the function logs in CloudWatch Logs. The implementation uses a Custom Resource to create the log group if it doesn't exist yet and to set the retention policy as discussed in aws#667. A retention policy of 1 day is set on the logs of the Lambda provider. The different retention days supported by CloudWatch Logs have been centralized in @aws-cdk/aws-logs. Some have been renamed to better match the console experience. Closes aws#667 BREAKING CHANGE: `cloudWatchLogsRetentionTimeDays` in @aws-cdk/aws-cloudtrail now uses a `logs.RetentionDays` instead of a `LogRetention`.
Adds a new property `logRetentionDays` on `Function` to control the log retention policy of the function logs in CloudWatch Logs. The implementation uses a Custom Resource to create the log group if it doesn't exist yet and to set the retention policy as discussed in aws#667. A retention policy of 1 day is set on the logs of the Lambda provider. The different retention days supported by CloudWatch Logs have been centralized in `@aws-cdk/aws-logs`. Some have been renamed to better match the console experience. Closes aws#667 BREAKING CHANGE: `cloudWatchLogsRetentionTimeDays` in `@aws-cdk/aws-cloudtrail` now uses a `logs.RetentionDays` instead of a `LogRetention`.
Do you guys think #2067 will practically resolve this? |
Adds a new property `logRetentionDays` on `Function` to control the log retention policy of the function logs in CloudWatch Logs. The implementation uses a Custom Resource to create the log group if it doesn't exist yet and to set the retention policy as discussed in #667. A retention policy of 1 day is set on the logs of the Lambda provider. The different retention days supported by CloudWatch Logs have been centralized in `@aws-cdk/aws-logs`. Some have been renamed to better match the console experience. Closes #667 BREAKING CHANGE: `cloudWatchLogsRetentionTimeDays` in `@aws-cdk/aws-cloudtrail` now uses a `logs.RetentionDays` instead of a `LogRetention`.
@rix0rrr Actually, this is possible by using some "depends on" statement straight in cloudformation.
This way, CFN creates role, lambda, log, policy in that order and doesn't race. Yeah you'll lose log if the invocation happens before the policy is created. Pick your poison for the time being I guess. I feel the problem is Lambda should accept the name of log group instead of hard defaulting to a magical name. Urghh.... |
@eladb when using #2067 on my existing lambda resource, it tried to create entirely new lambda function, not sure whether this is intended behavior. Looks like the issue can be solved by #2240 (comment). I will stick with creating log group relying on auto-generated log group name and configuring it - https://forums.aws.amazon.com/thread.jspa?threadID=260775 |
Those Log Groups are implicitly created by the services upon first execution, which makes it impossible to attach things like MetricFilters to them.
We need a Custom Resource that will make the LG if it doesn't exist yet, do nothing if it already exists.
The same LG can be used to set the retention policy on the LG.
The text was updated successfully, but these errors were encountered: