Skip to content

Commit 86a9e3f

Browse files
committed
feat(stream_io): Respect endpoint env vars and Boto3 endpoint configs
1 parent 6ecf0ab commit 86a9e3f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tensorizer/stream_io.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import boto3
2121
import botocore
2222
import botocore.exceptions
23+
import botocore.session
2324
import redis
2425

2526
import tensorizer._version as _version
@@ -1426,6 +1427,20 @@ def open_stream(
14261427

14271428
# Regardless of whether the config needed to be parsed,
14281429
# the endpoint gets a default value based on the operation.
1430+
# First, check for the AWS_ENDPOINT_URL environment variables,
1431+
# otherwise, check if botocore can resolve credentials,
1432+
# otherwise, use default_s3_write_endpoint and default_s3_read_endpoint.
1433+
if not s3_endpoint:
1434+
s3_endpoint = os.environ.get("AWS_ENDPOINT_URL_S3") or None
1435+
if not s3_endpoint:
1436+
s3_endpoint = os.environ.get("AWS_ENDPOINT_URL") or None
1437+
if not s3_endpoint:
1438+
scoped_config = botocore.session.Session().get_scoped_config()
1439+
s3_config = scoped_config.get("s3")
1440+
if s3_config:
1441+
s3_endpoint = s3_config.get("endpoint_url") or None
1442+
if not s3_endpoint:
1443+
s3_endpoint = scoped_config.get("endpoint_url") or None
14291444

14301445
if is_s3_upload:
14311446
s3_endpoint = s3_endpoint or default_s3_write_endpoint

0 commit comments

Comments
 (0)