Repository navigation
Python: [Bug]: BedrockEmbeddingClient ignores an explicit region when a boto3_session is passed, and reports the wrong region #9348
Description
Observed Behavior
BedrockEmbeddingClient picks its region differently from BedrockChatClient, and its region attribute does not match the region it sends requests to:
- With
region="us-west-2"(orBEDROCK_REGION) and aboto3_sessionfor eu-west-1, embedding requests go to eu-west-1. The explicit region is ignored, butclient.regionreports us-west-2. - With only a
boto3_sessionfor eu-west-1, requests go to eu-west-1, butclient.regionreports us-east-1. - Without a session, when boto3 finds a region in its own configuration (for example
AWS_DEFAULT_REGION), requests go to that region, butclient.regionreports us-east-1.
BedrockChatClient (since #9249) uses the explicit region first, then the session's region, then us-east-1, and its region attribute always matches the region it uses.
Expected Behavior
The embedding client uses the same order as the chat client: region / BEDROCK_REGION, then the region of boto3_session (or boto3's own configuration when no session is passed), then us-east-1. client.region reports the region that requests are actually sent to. Nothing changes when a pre-built client is passed.
Steps to Reproduce
- Make sure
BEDROCK_REGIONis not set. - Create a boto3 session for eu-west-1.
- Create
BedrockEmbeddingClientwithregion="us-west-2"and that session, and another one with only the session. - Compare the region of the runtime client with
client.region.
Minimal Reproduction
from boto3.session import Session
from agent_framework_bedrock import BedrockChatClient, BedrockEmbeddingClient
session = Session(region_name="eu-west-1")
embeddings = BedrockEmbeddingClient(model="amazon.titan-embed-text-v2:0", region="us-west-2", boto3_session=session)
chat = BedrockChatClient(model="<model id>", region="us-west-2", boto3_session=session)
print(embeddings._bedrock_client.meta.region_name, embeddings.region) # eu-west-1 us-west-2 (expected us-west-2 us-west-2)
print(chat._bedrock_client.meta.region_name, chat.region) # us-west-2 us-west-2
session_only = BedrockEmbeddingClient(model="amazon.titan-embed-text-v2:0", boto3_session=session)
print(session_only._bedrock_client.meta.region_name, session_only.region) # eu-west-1 us-east-1 (expected eu-west-1 eu-west-1)No AWS call is needed; boto3 builds the client offline.
The cause is in agent_framework_bedrock/_embedding_client.py: the runtime client is created with region_name=boto3_session.region_name or resolved_region, so the session's region wins over the configured one, while self.region is set to resolved_region (the configured region or us-east-1).
Error Messages and Stack Traces
No error. Requests go to a different region than the one configured (or reported), so they can fail on model availability or account access, or send data to an unexpected region.
Package Versions
agent-framework-bedrock: 1.0.0b261008 (main at b5e5521), agent-framework-core: 1.21.0, boto3: 1.43.107
Python Version
Python 3.12
Additional Context
I'd like to fix this. The change is a few lines in RawBedrockEmbeddingClient.__init__ (resolve the region in the same order as the chat client and report it) plus regression tests mirroring the chat client's region tests from #9249.
AI assistance: I used an AI coding assistant for the analysis and to draft this report. I reproduced and verified the behavior myself.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
kimnamu commentedon Oct 15, 2026
Thanks Md. Shalah Uddin (@shanto462) for the precise repro and for opening #9349 with tests that mirror #9249.
I get the same result on current main (cae4955, no
AWS_*/BEDROCK_*variables, no AWS config file). With #9349's source, the first four rows match the expected behavior in the issue:.region)region="us-west-2"+ session in eu-west-1BEDROCK_REGION=us-west-2+ session in eu-west-1AWS_DEFAULT_REGION=ap-southeast-2clientin eu-west-1 (out of scope per the issue)The cause matches the report:
_embedding_client.py:144lets the session region win, while:149reportsresolved_regionfrom:126. The chat client resolves once (_chat_client.py:325-326) and uses that value for both.Repro script, raw output, one adjacent note
The requests follow the runtime region, not
.region:Adjacent, for the last row: on the chat client
.regionalso buildsservice_url()(_chat_client.py:1064), so a pre-built eu-west-1 client returnshttps://bedrock-runtime.us-east-1.amazonaws.com.Happy to leave it with you. Claude (via Claude Code) assisted with the checks and this write-up; the outputs above are from local runs.