22from time import time
33from typing import Any , Optional
44
5- from litdata .constants import _BOTO3_AVAILABLE
5+ from litdata .constants import _BOTO3_AVAILABLE , _IS_IN_STUDIO
66
77if _BOTO3_AVAILABLE :
88 import boto3
@@ -17,15 +17,14 @@ class S3Client:
1717 def __init__ (self , refetch_interval : int = 3300 ) -> None :
1818 self ._refetch_interval = refetch_interval
1919 self ._last_time : Optional [float ] = None
20- self ._has_cloud_space_id : bool = "LIGHTNING_CLOUD_SPACE_ID" in os .environ
2120 self ._client : Optional [Any ] = None
2221
2322 def _create_client (self ) -> None :
2423 has_shared_credentials_file = (
2524 os .getenv ("AWS_SHARED_CREDENTIALS_FILE" ) == os .getenv ("AWS_CONFIG_FILE" ) == "/.credentials/.aws_credentials"
2625 )
2726
28- if has_shared_credentials_file :
27+ if has_shared_credentials_file or not _IS_IN_STUDIO :
2928 self ._client = boto3 .client (
3029 "s3" , config = botocore .config .Config (retries = {"max_attempts" : 1000 , "mode" : "adaptive" })
3130 )
@@ -42,10 +41,9 @@ def _create_client(self) -> None:
4241
4342 @property
4443 def client (self ) -> Any :
45- if not self ._has_cloud_space_id :
46- if self ._client is None :
47- self ._create_client ()
48- return self ._client
44+ if self ._client is None :
45+ self ._create_client ()
46+ self ._last_time = time ()
4947
5048 # Re-generate credentials for EC2
5149 if self ._last_time is None or (time () - self ._last_time ) > self ._refetch_interval :
0 commit comments