-
Notifications
You must be signed in to change notification settings - Fork 4.2k
fix(kinesisfirehose): can't call grantPrincipal multiple times #34682
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
base: main
Are you sure you want to change the base?
fix(kinesisfirehose): can't call grantPrincipal multiple times #34682
Conversation
…on multiple grantPrincipal calls
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.
(This review is outdated)
Exemption Request We know at the unit test level whether this bug has been resolved |
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.
Left some minor comments
@@ -402,6 +402,15 @@ describe('delivery stream', () => { | |||
expect(deliveryStream.grantPrincipal).toBeInstanceOf(iam.Role); | |||
}); | |||
|
|||
test('multiple calls to grantPrincipal should return the same instance of IAM 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.
While the test is good, it could be more explicit about what's being tested. The test name indicates it's checking that multiple calls return the same instance, but the first assertion is actually checking that it doesn't throw an error. Consider splitting this into two separate tests or making the test name more explicit about both behaviors being tested
} | ||
// backwards compatibility | ||
return new iam.Role(this, 'Service Role', { | ||
// backwards compatibility - create role only once |
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 comment backwards compatibility
doesn't fully explain the purpose of this change. It's not just for backwards compatibility but also to fix a bug where multiple calls to grantPrincipal would create multiple roles with the same name. Improve the comment to better explain the purpose. Maybe something like:
Create the role only once to ensure multiple calls to grantPrincipal return the same role instance, while maintaining backwards compatibility
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
Issue # (if applicable)
Closes #.
Reason for this change
DeliveryStream creates a new iam.Role every reference grantPrincipal, so we get the error
There is already a Construct with name 'Service Role' in DeliveryStream [Delivery Stream Multiple]
. This is easy to reproduce if you use deliveryStream with multiplegrantXXX
methods.This is test result before fix codes.
Description of changes
I changed grantPrincipal implementation from create a new iam.Role every reference to create a new iam.Role only at first reference.
Describe any new or updated permissions being added
None.
Description of how you validated changes
Create the new unit test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license