Skip to content

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

Merged

Conversation

WinterYukky
Copy link
Contributor

@WinterYukky WinterYukky commented Jun 11, 2025

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 multiple grantXXX methods.

This is test result before fix codes.

yarn test aws-kinesisfirehose/test/delivery-stream.test.ts -t 
"multiple calls to grantPrincipal should return the same instance of IAM role"
yarn run v1.22.22
$ jest aws-kinesisfirehose/test/delivery-stream.test.ts -t 'multiple calls to grantPrincipal should return the same instance of IAM role'
ts-jest[config] (WARN) 
    The "ts-jest" config option "isolatedModules" is deprecated and will be removed in v30.0.0. Please use "isolatedModules: true" in /workspaces/aws-cdk/packages/aws-cdk-lib/tsconfig.json instead, see https://www.typescriptlang.org/tsconfig/#isolatedModules
  
 FAIL  aws-kinesisfirehose/test/delivery-stream.test.ts
  delivery stream
    ✕ multiple calls to grantPrincipal should return the same instance of IAM role (45 ms)
    ○ other tests...

  ● delivery stream › multiple calls to grantPrincipal should return the same instance of IAM role

    expect(received).not.toThrow()

    Error name:    "Error"
    Error message: "There is already a Construct with name 'Service Role' in DeliveryStream [Delivery Stream Multiple]"

          155 |
          156 |   constructor(scope: Construct, id: string, props: ResourceProps = {}) {
        > 157 |     super(scope, id);
              |     ^
          158 |
          159 |     if ((props.account !== undefined || props.region !== undefined) && props.environmentFromArn !== undefined) {
          160 |       throw new ValidationError(`Supply at most one of 'account'/'region' (${props.account}/${props.region}) and 'environmentFromArn' (${props.environmentFromArn})`, this);

          at Node.addChild (../../node_modules/constructs/src/construct.ts:430:13)
          at new Node (../../node_modules/constructs/src/construct.ts:71:17)
          at new Construct (../../node_modules/constructs/src/construct.ts:482:17)
          at new Resource (core/lib/resource.ts:157:5)
          at new Role (aws-iam/lib/role.ts:472:5)
          at new Role (core/lib/prop-injectable.ts:36:7)
          at WrappedClass.get grantPrincipal [as grantPrincipal] (aws-kinesisfirehose/lib/delivery-stream.ts:320:26)
          at aws-kinesisfirehose/test/delivery-stream.test.ts:410:33
          at Object.<anonymous> (../../node_modules/expect/build/toThrowMatchers.js:74:11)
          at Object.throwingMatcher [as toThrow] (../../node_modules/expect/build/index.js:320:21)
          at Object.<anonymous> (aws-kinesisfirehose/test/delivery-stream.test.ts:410:53)

      408 |     });
      409 |     const principal = deliveryStream.grantPrincipal;
    > 410 |     expect(() => deliveryStream.grantPrincipal).not.toThrow();
          |                                                     ^
      411 |     expect(deliveryStream.grantPrincipal).toBe(principal);
      412 |   });
      413 |

      at Object.<anonymous> (aws-kinesisfirehose/test/delivery-stream.test.ts:410:53)

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

@aws-cdk-automation aws-cdk-automation requested a review from a team June 11, 2025 09:28
@github-actions github-actions bot added p2 admired-contributor [Pilot] contributed between 13-24 PRs to the CDK labels Jun 11, 2025
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a 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)

@WinterYukky
Copy link
Contributor Author

Exemption Request

We know at the unit test level whether this bug has been resolved

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jun 11, 2025
@aws-cdk-automation aws-cdk-automation added pr/needs-maintainer-review This PR needs a review from a Core Team Member and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jun 11, 2025
@ozelalisen ozelalisen self-assigned this Jun 16, 2025
Copy link
Member

@ozelalisen ozelalisen left a 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

}
// backwards compatibility
return new iam.Role(this, 'Service Role', {
// backwards compatibility - create role only once
Copy link
Member

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

@ozelalisen ozelalisen added pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. labels Jun 16, 2025
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jun 16, 2025
@aws-cdk-automation aws-cdk-automation dismissed their stale review June 16, 2025 15:06

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation
Copy link
Collaborator

This PR has been in the CHANGES REQUESTED state for 3 weeks, and looks abandoned. Note that PRs with failing linting check or builds are not reviewed, please ensure your build is passing

To prevent automatic closure:

  • Resume work on the PR
  • OR request an exemption by adding a comment containing 'Exemption Request' with justification e.x "Exemption Request: "
  • OR request clarification by adding a comment containing 'Clarification Request' with a question e.x "Clarification Request: "

This PR will automatically close in 14 days if no action is taken.

@mergify mergify bot dismissed ozelalisen’s stale review July 15, 2025 07:52

Pull request has been modified.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jul 15, 2025
Copy link
Member

@ozelalisen ozelalisen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

mergify bot commented Jul 15, 2025

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).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 3675508
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

mergify bot commented Jul 15, 2025

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).

@mergify mergify bot merged commit ea226b5 into aws:main Jul 15, 2025
18 checks passed
Copy link
Contributor

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK p2 pr/needs-maintainer-review This PR needs a review from a Core Team Member pr-linter/exempt-integ-test The PR linter will not require integ test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants