2
2
from time import time
3
3
from typing import Any , Optional
4
4
5
- from lightning .data .constants import _BOTO3_AVAILABLE
5
+ from lightning .data .constants import _BOTO3_AVAILABLE , _IS_IN_STUDIO
6
6
7
7
if _BOTO3_AVAILABLE :
8
8
import boto3
@@ -17,15 +17,14 @@ class S3Client:
17
17
def __init__ (self , refetch_interval : int = 3300 ) -> None :
18
18
self ._refetch_interval = refetch_interval
19
19
self ._last_time : Optional [float ] = None
20
- self ._has_cloud_space_id : bool = "LIGHTNING_CLOUD_SPACE_ID" in os .environ
21
20
self ._client : Optional [Any ] = None
22
21
23
22
def _create_client (self ) -> None :
24
23
has_shared_credentials_file = (
25
24
os .getenv ("AWS_SHARED_CREDENTIALS_FILE" ) == os .getenv ("AWS_CONFIG_FILE" ) == "/.credentials/.aws_credentials"
26
25
)
27
26
28
- if has_shared_credentials_file :
27
+ if has_shared_credentials_file or not _IS_IN_STUDIO :
29
28
self ._client = boto3 .client (
30
29
"s3" , config = botocore .config .Config (retries = {"max_attempts" : 1000 , "mode" : "adaptive" })
31
30
)
@@ -42,10 +41,9 @@ def _create_client(self) -> None:
42
41
43
42
@property
44
43
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 ()
49
47
50
48
# Re-generate credentials for EC2
51
49
if self ._last_time is None or (time () - self ._last_time ) > self ._refetch_interval :
0 commit comments