Skip to content

feat: update AWS Bedrock cross-region inference profile mapping, Closed issue #2704 #4973

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

KevinZhao
Copy link

@KevinZhao KevinZhao commented Jun 21, 2025

Related GitHub Issue

Closes: # <2704>
#2704

Description

Test Procedure

Type of Change

  • [x ] 🐛 Bug Fix: Non-breaking change that fixes an issue.
  • New Feature: Non-breaking change that adds functionality.
  • 💥 Breaking Change: Fix or feature that would cause existing functionality to not work as expected.
  • ♻️ Refactor: Code change that neither fixes a bug nor adds a feature.
  • 💅 Style: Changes that do not affect the meaning of the code (white-space, formatting, etc.).
  • 📚 Documentation: Updates to documentation files.
  • ⚙️ Build/CI: Changes to the build process or CI configuration.
  • 🧹 Chore: Other changes that don't modify src or test files.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Code Quality:
    • My code adheres to the project's style guidelines.
    • There are no new linting errors or warnings (npm run lint).
    • All debug code (e.g., console.log) has been removed.
  • Testing:
    • New and/or updated tests have been added to cover my changes.
    • All tests pass locally (npm test).
    • The application builds successfully with my changes.
  • Branch Hygiene: My branch is up-to-date (rebased) with the main branch.
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Changeset: A changeset has been created using npm run changeset if this PR includes user-facing changes or dependency updates.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

Additional Notes

Get in Touch


Important

Updates AWS Bedrock cross-region inference profile mapping to use AWS's recommended inference profiles, addressing issue #2704.

  • Behavior:
    • Updates getPrefixForRegion() in bedrock.ts to use AWS recommended inference profiles for cross-region inference.
    • Adds AWS_INFERENCE_PROFILE_MAPPING in bedrock.ts for mapping regions to inference profiles.
  • Classes:
    • Updates AwsBedrockHandler in bedrock.ts to apply cross-region inference prefixes using AWS_INFERENCE_PROFILE_MAPPING.
  • Misc:

This description was created by Ellipsis for 5be82b9. You can customize this summary. It will automatically update as commits are pushed.

- Add AWS_INFERENCE_PROFILE_MAPPING with official inference profile prefixes
- Update getPrefixForRegion to use AWS recommended inference profiles
- Improve region-to-profile mapping based on AWS documentation
- Prioritize more specific region patterns (e.g., us-gov- before us-)
- Add support for apac., ca., sa., and ug. inference profiles
@KevinZhao KevinZhao requested review from mrubens, cte and jr as code owners June 21, 2025 07:35
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jun 21, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Jun 21, 2025
@daniel-lxs daniel-lxs moved this from Triage to PR [Needs Prelim Review] in Roo Code Roadmap Jun 21, 2025
@hannesrudolph hannesrudolph added PR - Needs Preliminary Review and removed Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. labels Jun 21, 2025
Copy link
Collaborator

@daniel-lxs daniel-lxs left a comment

Choose a reason for hiding this comment

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

Hey @KevinZhao, thank you for your PR!

This looks like a solid implementation, I left some suggestions to hopefully get this ready and merged.

Let me know what you think!

return prefix
// Use AWS recommended inference profile prefixes
// Sort by prefix length (descending) to ensure more specific prefixes match first (e.g., us-gov- before us-)
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we add a comment explaining this? It would help future maintainers understand why the sorting is necessary:

// Sort by prefix length (descending) to ensure more specific prefixes match first
// This prevents "us-" from matching "us-gov-" regions, for example
const sortedMappings = Object.entries(AWS_INFERENCE_PROFILE_MAPPING).sort(([a], [b]) => b.length - a.length)

// Europe regions → eu. inference profile
"eu-": "eu.",
// Asia Pacific regions → apac. inference profile (updated per AWS documentation)
"ap-": "apac.",
Copy link
Collaborator

Choose a reason for hiding this comment

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

I notice the comment mentions "apac." as the updated prefix per AWS documentation, which is great. However, the existing BEDROCK_REGION_INFO object below (lines 422-427) still contains the old "ap." prefix entry. Is this intentional for backward compatibility? If so, it might be worth adding a note to clarify the relationship between the old and new prefixes.

@@ -978,11 +977,16 @@ export class AwsBedrockHandler extends BaseProvider implements SingleCompletionH
}

private static getPrefixForRegion(region: string): string | undefined {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be helpful to add test coverage for this new getPrefixForRegion method? I noticed there are existing tests for cross-region inference in bedrock-custom-arn.spec.ts, but they don't specifically test the new mapping logic. Some test cases to consider:

  • Testing that ap-northeast-1 returns "apac."
  • Testing that us-gov-west-1 returns "ug." (not "us.")
  • Testing that an unknown region pattern returns undefined

This would help ensure the mapping works correctly and prevent regressions.

@daniel-lxs daniel-lxs moved this from PR [Needs Prelim Review] to PR [Changes Requested] in Roo Code Roadmap Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working PR - Changes Requested size:M This PR changes 30-99 lines, ignoring generated files.
Projects
Status: PR [Changes Requested]
Development

Successfully merging this pull request may close these issues.

3 participants