Skip to content

Commit df6bf5b

Browse files
committed
feat(session): add endpoint_url parameter to S3SessionManager
Forwards an optional endpoint_url to the boto3 S3 client, enabling use with S3-compatible backends such as MinIO or LocalStack. Follows the same pattern as BedrockModel, which already accepts endpoint_url as a constructor parameter. Closes #1794
1 parent 94fc8dd commit df6bf5b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

src/strands/session/s3_session_manager.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ def __init__(
5151
boto_session: boto3.Session | None = None,
5252
boto_client_config: BotocoreConfig | None = None,
5353
region_name: str | None = None,
54+
endpoint_url: str | None = None,
5455
**kwargs: Any,
5556
):
5657
"""Initialize S3SessionManager with S3 storage.
@@ -63,6 +64,8 @@ def __init__(
6364
boto_session: Optional boto3 session
6465
boto_client_config: Optional boto3 client configuration
6566
region_name: AWS region for S3 storage
67+
endpoint_url: Custom endpoint URL for S3-compatible storage (e.g., MinIO, LocalStack).
68+
When set, requests are sent to this URL instead of the default AWS S3 endpoint.
6669
**kwargs: Additional keyword arguments for future extensibility.
6770
"""
6871
self.bucket = bucket
@@ -82,7 +85,7 @@ def __init__(
8285
else:
8386
client_config = BotocoreConfig(user_agent_extra="strands-agents")
8487

85-
self.client = session.client(service_name="s3", config=client_config)
88+
self.client = session.client(service_name="s3", config=client_config, endpoint_url=endpoint_url)
8689
super().__init__(session_id=session_id, session_repository=self)
8790

8891
def _get_session_path(self, session_id: str) -> str:

tests/strands/session/test_s3_session_manager.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ def test_init_s3_session_manager_with_existing_user_agent(mocked_aws, s3_bucket)
8989
assert "strands-agents" in session_manager.client.meta.config.user_agent_extra
9090

9191

92+
def test_init_s3_session_manager_with_endpoint_url():
93+
from unittest.mock import patch
94+
95+
from strands.session.repository_session_manager import RepositorySessionManager
96+
97+
endpoint = "http://localhost:9000"
98+
with patch("boto3.Session.client") as mock_client:
99+
mock_client.return_value = Mock()
100+
# Skip session initialization so no S3 calls are made
101+
with patch.object(RepositorySessionManager, "__init__", return_value=None):
102+
S3SessionManager(session_id="test", bucket="my-bucket", endpoint_url=endpoint)
103+
104+
_, kwargs = mock_client.call_args
105+
assert kwargs.get("endpoint_url") == endpoint
106+
107+
92108
def test_empty_prefix_session_roundtrip(mocked_aws, s3_bucket, sample_session, sample_agent):
93109
"""Test that session data can be written and read back with default empty prefix."""
94110
manager = S3SessionManager(session_id="test", bucket=s3_bucket, prefix="", region_name="us-west-2")

0 commit comments

Comments
 (0)