-
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
fix(redshift-alpha): use same role for database-query singleton function #32363
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #32363 +/- ##
=======================================
Coverage 66.96% 66.96%
=======================================
Files 329 329
Lines 18663 18663
Branches 3258 3258
=======================================
Hits 12497 12497
Misses 5839 5839
Partials 327 327
Flags with carried forward coverage won't be shown. Click here to find out more.
|
c1402b3
to
e5a6c7b
Compare
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.
...shot/asset.c973f9a285ae54986627703f13cdd21d38dcdb3cf29620c5411d7d3baa53a3b9/redshift-data.js
Fixed
Show fixed
Hide fixed
e9a9b6b
to
ea8b8f0
Compare
ea8b8f0
to
cc05f22
Compare
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
a63c2a2
to
4331a07
Compare
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 @5d for fixing this. Left some nit comments.
/** | ||
* The name of the singleton function. It acts as a unique ID within its CDK stack. | ||
* */ | ||
public readonly constructName: string; |
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 we can use the existing property itself using functionName to get the name of the function. Don't think we need a new property here.
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.
From my understanding, the functionName of a singleton Lambda differs from the constructName used to identify the function within the stack. Additionally, the functionName is often a token and is typically only resolved at deployment time.
* We only need one function since it's just acting as a trigger. | ||
* */ | ||
private getProviderRole(handler: lambda.SingletonFunction): iam.IRole { | ||
const id = handler.constructName + 'ProviderRole'; |
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: we could get the function name like below
const id = handler.functionName + 'ProviderRole';
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.
ditto
* Get or create the IAM role for the singleton lambda function. | ||
* We only need one function since it's just acting as a trigger. | ||
* */ | ||
private getProviderRole(handler: lambda.SingletonFunction): iam.IRole { |
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: Since the method returns either an existing role or creates a new role, i think we can rename the method name to be
getOrCreateLambdaProviderRole
for better readability. - Can we have a unit test for this method to get an existing role and create a new role?
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, will update the function name. I will add the unit test case for it.
@@ -112,6 +112,8 @@ abstract class UserBase extends Construct implements IUser { | |||
...this.databaseProps, | |||
user: this, | |||
}); | |||
|
|||
this.privileges.node.addDependency(table); |
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.
just for my understanding, why do we need this to be add as dependency?
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.
I've encountered errors during stack deletion when the table is removed before its associated privileges are deleted.
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.
I suggest adding the reason as a code comment.
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.
sure, will add a comment to it.
@@ -64,6 +64,7 @@ export class DatabaseQuery<HandlerProps> extends Construct implements iam.IGrant | |||
|
|||
const provider = new customresources.Provider(this, 'Provider', { | |||
onEventHandler: handler, | |||
role: this.getProviderRole(handler), |
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.
Is it possible to use handler.role
(so everything about the singleton lambda is nicely scoped inside the SingletonFunction
instance and you don't need to add the constructName
)?
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 handler in this case is the singleton lambda function. However, the role is not associated to the handler. Instead, the role is assumed by the custom resource provider, which is responsible for triggering the handler.
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.
I see! Thank you.
@@ -112,6 +112,8 @@ abstract class UserBase extends Construct implements IUser { | |||
...this.databaseProps, | |||
user: this, | |||
}); | |||
|
|||
this.privileges.node.addDependency(table); |
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.
I suggest adding the reason as a code comment.
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.
QQ: Is there any reason of adding the feature flag context file into integ-runner for this PR?
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.
oh, it's auto generated. I will remove it
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #32089.
Reason for this change
The Redshift tables use a singleton function as the invoker for various custom resource onEvent Lambda functions. Currently, each custom resource lambda function has a dedicated IAM role to assume. However, since it’s the same singleton function, a shared role could achieve the same outcome.
Description of changes
Use the same IAM role for the singleton invoker function to assume.
Description of how you validated changes
deployed to my local stack
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license