Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/strands/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,17 @@ def __init__(

logger.debug("config=<%s> | initializing", self.config)

region_for_boto = region_name or os.getenv("AWS_REGION")
if region_for_boto is None:
region_for_boto = "us-west-2"
logger.warning("defaulted to us-west-2 because no region was specified")
logger.warning(
"issue=<%s> | this behavior will change in an upcoming release",
"https://github.com/strands-agents/sdk-python/issues/238",
)

session = boto_session or boto3.Session(
region_name=region_name or os.getenv("AWS_REGION") or "us-west-2",
region_name=region_for_boto,
)

# Add strands-agents to the request user agent
Expand Down
2 changes: 1 addition & 1 deletion src/strands/types/models/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def format_request_message_content(cls, content: ContentBlock) -> dict[str, Any]
base64.b64decode(image_bytes, validate=True)
logger.warning(
"issue=<%s> | base64 encoded images will not be accepted in a future version",
"https://github.com/strands-agents/sdk-python/issues/252"
"https://github.com/strands-agents/sdk-python/issues/252",
)
except ValueError:
image_bytes = base64.b64encode(image_bytes)
Expand Down
17 changes: 17 additions & 0 deletions tests/strands/models/test_bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ def test__init__default_model_id(bedrock_client):
assert tru_model_id == exp_model_id


def test__init__with_default_region(bedrock_client):
"""Test that BedrockModel uses the provided region."""
_ = bedrock_client
default_region = "us-west-2"

with unittest.mock.patch("strands.models.bedrock.boto3.Session") as mock_session_cls:
with unittest.mock.patch("strands.models.bedrock.logger.warning") as mock_warning:
_ = BedrockModel()
mock_session_cls.assert_called_once_with(region_name=default_region)
# Assert that warning logs are emitted
mock_warning.assert_any_call("defaulted to us-west-2 because no region was specified")
mock_warning.assert_any_call(
"issue=<%s> | this behavior will change in an upcoming release",
"https://github.com/strands-agents/sdk-python/issues/238",
)


def test__init__with_custom_region(bedrock_client):
"""Test that BedrockModel uses the provided region."""
_ = bedrock_client
Expand Down