Skip to content

feat(bedrock-agentcore): add grantInvokeWithWebSocketStream method to Runtime #37508

Open
mazyu36 wants to merge 4 commits intoaws:mainfrom
mazyu36:fix/issue-37495-grant-invoke-websocket-stream
Open

feat(bedrock-agentcore): add grantInvokeWithWebSocketStream method to Runtime #37508
mazyu36 wants to merge 4 commits intoaws:mainfrom
mazyu36:fix/issue-37495-grant-invoke-websocket-stream

Conversation

@mazyu36
Copy link
Copy Markdown
Contributor

@mazyu36 mazyu36 commented Apr 2, 2026

Issue # (if applicable)

Closes #37495

Reason for this change

grantInvoke does not grant bedrock-agentcore:InvokeAgentRuntimeWithWebSocketStream, so roles cannot invoke AgentCore Runtimes via WebSocket stream.

Description of changes

Add two new grant methods to IBedrockAgentRuntime and RuntimeBase:

  • grantInvokeWithWebSocketStream — grants bedrock-agentcore:InvokeAgentRuntimeWithWebSocketStream
  • grantInvokeWithWebSocketStreamForUser — grants bedrock-agentcore:InvokeAgentRuntimeWithWebSocketStreamForUser

This follows the same pattern as the existing grantInvokeRuntime / grantInvokeRuntimeForUser methods, and is consistent with how CDK separates invocation channels (e.g. Lambda's grantInvoke vs grantInvokeUrl, API Gateway v2's grantManageConnections).

grantInvoke is intentionally left unchanged — users who need WebSocket stream access can call the new methods explicitly.

References:

Description of how you validated changes

  • 6 new unit tests added and passing:
    • grantInvokeWithWebSocketStream: permission grant, imported runtime, Grant object
    • grantInvokeWithWebSocketStreamForUser: permission grant, imported runtime, Grant object

Checklist

  • My code adheres to the CONTRIBUTING GUIDE and DESIGN GUIDELINES
  • Is this a breaking change? No
  • Does this introduce a new feature? Yes — grantInvokeWithWebSocketStream and grantInvokeWithWebSocketStreamForUser

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

… Runtime

Add `grantInvokeWithWebSocketStream` to `IBedrockAgentRuntime` and `RuntimeBase`
to grant `bedrock-agentcore:InvokeAgentRuntimeWithWebSocketStream` permission,
enabling WebSocket stream invocation of AgentCore Runtimes.

Closes aws#37495
@github-actions github-actions bot added bug This issue is a bug. p2 labels Apr 2, 2026
@aws-cdk-automation aws-cdk-automation requested a review from a team April 2, 2026 12:40
@github-actions github-actions bot added the distinguished-contributor [Pilot] contributed 50+ PRs to the CDK label Apr 2, 2026
Copy link
Copy Markdown
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.

The pull request linter fails with the following errors:

❌ Features must contain a change to an integration test file and the resulting snapshot.

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.

✅ A exemption request has been requested. Please wait for a maintainer's review.

@mazyu36
Copy link
Copy Markdown
Contributor Author

mazyu36 commented Apr 2, 2026

Exemption Request: the change only adds a different IAM action string to an existing grant pattern.

@aws-cdk-automation aws-cdk-automation added the pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. label Apr 2, 2026
@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Apr 2, 2026
@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 Apr 2, 2026
@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Apr 8, 2026
@mazyu36 mazyu36 changed the title feat(bedrock-agentcore): add grantInvokeWithWebSocketStream method to Runtime feat(bedrock-agentcore): add grantInvokeWithWebSocketStream method to Runtime Apr 9, 2026
Copy link
Copy Markdown
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.

Thanks for the clean PR @mazyu36 — the implementation is consistent with existing grant patterns and test coverage looks solid. A couple of suggestions for the maintainers to consider:

  • JSDoc on grantInvoke

One thing I noticed is that grantInvoke doesn't mention it excludes WebSocket stream permissions. This is essentially what caused #37495 — users call grantInvoke expecting full access, then hit silent auth failures when using WebSocket. It might be worth updating the JSDoc to call this out explicitly, something like:

/**
 * Permits an IAM principal to invoke this runtime via HTTP and on behalf of a user.
 * Grants both InvokeAgentRuntime and InvokeAgentRuntimeForUser permissions.
 *
 * NOTE: This does not grant WebSocket stream permissions.
 * Use {@link grantInvokeWithWebSocketStream} or
 * {@link grantInvokeWithWebSocketStreamForUser} for WebSocket access.
 *
 * @param grantee The 
 * principal to grant access to
 */
  • Idea: grantInvokeAll() convenience method

With this PR, users who want full invoke access would need to call multiple grant methods. A grantInvokeAll() that covers all four actions in one call could be a nice DX improvement. Just a thought — happy to leave this to the maintainers to decide if it's worth the added surface area.

Overall this looks good to me 👍

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. distinguished-contributor [Pilot] contributed 50+ PRs to the CDK p2 pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(@aws-cdk/bedrock-agentcore-alpha): grantInvoke should grant invoking as a websocket

4 participants