Skip to content

Conversation

mellevanderlinde
Copy link
Contributor

@mellevanderlinde mellevanderlinde commented Jul 31, 2025

Issue # (if applicable)

Closes #35120

Reason for this change

Dependency on permission was only applied to new roles, not to existing roles.

Description of changes

The dependency on permission now applies to both new and existing roles.

Describe any new or updated permissions being added

Not applicable.

Description of how you validated changes

I've added an integration test for an agent with an existing/custom role attached to it.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added the repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK label Jul 31, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team July 31, 2025 19:25
@github-actions github-actions bot added bug This issue is a bug. effort/medium Medium work item – several days of effort p2 labels Jul 31, 2025
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 31, 2025
Copy link
Contributor

@pahud pahud left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

Consider to add a unit test that explicitly verifies grant.applyBefore() is called for existing roles:

   test('applies dependency for existing role', () => {
     const existingRole = new iam.Role(stack, 'ExistingRole', {
       assumedBy: new iam.ServicePrincipal('bedrock.amazonaws.com'),
     });

     new Agent(stack, 'Agent', {
       instruction: 'test',
       foundationModel: BedrockFoundationModel.ANTHROPIC_CLAUDE_3_5_SONNET_V2_0,
       existingRole,
     });

     // Verify CloudFormation template has DependsOn
     const template = Template.fromStack(stack);
     template.hasResource('AWS::Bedrock::Agent', {
       DependsOn: [Match.stringLikeRegexp('.*DefaultPolicy.*')]
     });
   });

@mellevanderlinde
Copy link
Contributor Author

@pahud That was indeed missing, I've added a test for existing roles and roles created by the Agent construct

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

@pahud
Copy link
Contributor

pahud commented Aug 5, 2025

LGTM! Thanks!

@pahud pahud 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 Aug 5, 2025
@aws-cdk-automation aws-cdk-automation added pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. and removed pr/needs-maintainer-review This PR needs a review from a Core Team Member labels Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/medium Medium work item – several days of effort p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bedrock: Access denied for operation 'AWS::Bedrock::Agent'
3 participants