-
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
Changes from 9 commits
daece0a
2500815
a998017
8f89f02
06e8851
4331a07
8723099
e89b32b
6c0f908
13b536f
af94e56
03a3946
751a303
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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), | ||
}); | ||
|
||
const queryHandlerProps: DatabaseQueryHandlerProps & HandlerProps = { | ||
|
@@ -116,4 +117,19 @@ export class DatabaseQuery<HandlerProps> extends Construct implements iam.IGrant | |
} | ||
return adminUser; | ||
} | ||
|
||
/** | ||
* 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 commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
const id = handler.constructName + 'ProviderRole'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we could get the function name like below
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
const existing = cdk.Stack.of(this).node.tryFindChild(id); | ||
return existing != null | ||
? existing as iam.Role | ||
: new iam.Role(cdk.Stack.of(this), id, { | ||
assumedBy: new iam.ServicePrincipal('lambda.amazonaws.com'), | ||
managedPolicies: [iam.ManagedPolicy.fromAwsManagedPolicyName('service-role/AWSLambdaBasicExecutionRole')], | ||
}); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. sure, will add a comment to it. |
||
} | ||
|
||
this.privileges.addPrivileges(table, ...actions); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 theSingletonFunction
instance and you don't need to add theconstructName
)?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.