From b4675973df9b5d5923c73069d46b6d83256329e3 Mon Sep 17 00:00:00 2001 From: Mackenzie Zastrow Date: Thu, 19 Jun 2025 10:46:21 -0400 Subject: [PATCH] fix: Omit warning that us-west-2 will not be the default region Related to #238 --- src/strands/models/bedrock.py | 11 ++++++++++- src/strands/types/models/openai.py | 2 +- tests/strands/models/test_bedrock.py | 17 +++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/strands/models/bedrock.py b/src/strands/models/bedrock.py index 9bbcca7d0..92472b71f 100644 --- a/src/strands/models/bedrock.py +++ b/src/strands/models/bedrock.py @@ -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 diff --git a/src/strands/types/models/openai.py b/src/strands/types/models/openai.py index 0df1dda55..a5c268921 100644 --- a/src/strands/types/models/openai.py +++ b/src/strands/types/models/openai.py @@ -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) diff --git a/tests/strands/models/test_bedrock.py b/tests/strands/models/test_bedrock.py index b326eee73..137b57c8c 100644 --- a/tests/strands/models/test_bedrock.py +++ b/tests/strands/models/test_bedrock.py @@ -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