-
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
feat(s3): add autoDeleteObjectsLogGroup
to pass log group to custom resource lambda
#30333
feat(s3): add autoDeleteObjectsLogGroup
to pass log group to custom resource lambda
#30333
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
0efae66
to
e554487
Compare
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for making this change!
I see from this #24815 (comment) comment from the linked issue that someone made a similar prototype and they faced this error.
An unexpected behavior was that the provider lambda was re-creating the log group after I got it to successfully delete itself on stack deletion, but the new log group came back with infinite duration (argh!). This is because the default role for the lambda has permission to create a log group (which was occurring when it issued a final log stream on delete). Fortunately policyStatements was already wired up so I just explicitly denied CreateLogGroup for the Lambda role.
Wondering if you faced something similar (I see similarities between the prototype and your change so just checking)
*/ | ||
readonly autoDeleteObjectsLogGroup?: logs.ILogGroup; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if autoDeleteObjectsLogGroup
is set but autoDeleteObjects
isn't set to true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is ignored.
```ts | ||
import { ILogGroup } from 'aws-cdk-lib/aws-logs'; | ||
|
||
declare const logGroup: ILogGroup; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think its more valuable if you actually define a log group here. The log group from the integ test should do.
declare const logGroup: ILogGroup; | |
const logGroup = new logs.LogGroup(this, 'LogGroup', { | |
logGroupName: 'AutoDeleteObjectsLambdaLogs', | |
retention: logs.RetentionDays.THREE_DAYS, | |
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My first revision was defining the log group explicitly. But I found the Lambda REAME that uses this style. But I agree defining the log group is more valuable to the reader. Will update
Template.fromStack(stack).hasResourceProperties('AWS::Lambda::Function', { | ||
LoggingConfig: { | ||
LogGroup: { | ||
'Ref': 'LogGroup106AAD846', | ||
}, | ||
}, | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we also be checking if the log group resource was created?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea. Will update
Let me try reproducing the issue and get back to you. From your call out, I realized the integ test is not generating expected template, namely, the |
This PR has a problem with the integ test. Looking at the snapshot, it is apparent that the log group is created but it is not referenced anywhere in the template. The expected template should have the custom resource lambda referencing the log group like so:
Upon further investigation, I have learned that the
With the above, the approach in this PR creates a poor UX as user must remember to set the |
Issue # (if applicable)
Closes #24815.
Reason for this change
To allow log group customization on the custom resource lambda created for the
autoDeleteObjects
feature.Description of changes
There are 2 changes to implement the
autoDeleteObjectsLogGroup
prop:CustomResourceProviderBase
is updated to accept an optionallogGroupName
prop. If it is defined, it will be passed to theAWS::Lambda::Function
resource definition (namely, setting theLoggingConfig
prop).s3.Bucket
is updated to accept an optionalautoDeleteObjectsLogGroup
prop. The idea is to make the API experience similar to thelogGroup
prop onlambda.Function
.Description of how you validated changes
Unit tests have been added for both the
s3.Bucket
class andcore.CustomResourceProvider
classChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license