File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change @@ -132,12 +132,7 @@ impl<RT: Runtime> S3Storage<RT> {
132132        key_prefix :  String , 
133133        runtime :  RT , 
134134    )  -> anyhow:: Result < Self >  { 
135-         let  config = must_s3_config_from_env ( ) 
136-             . context ( "AWS env variables are required when using S3 storage" ) ?
137-             . retry_config ( RetryConfig :: standard ( ) ) 
138-             . load ( ) 
139-             . await ; 
140-         let  client = Client :: new ( & config) ; 
135+         let  client = s3_client ( ) . await ?; 
141136        let  storage = Self  { 
142137            client, 
143138            bucket, 
@@ -157,6 +152,22 @@ impl<RT: Runtime> S3Storage<RT> {
157152    } 
158153} 
159154
155+ async  fn  s3_client ( )  -> Result < Client ,  anyhow:: Error >  { 
156+     static  S3_CLIENT :  tokio:: sync:: OnceCell < Client >  = tokio:: sync:: OnceCell :: const_new ( ) ; 
157+     let  client = S3_CLIENT 
158+         . get_or_try_init ( || async  { 
159+             let  config = must_s3_config_from_env ( ) 
160+                 . context ( "AWS env variables are required when using S3 storage" ) ?
161+                 . retry_config ( RetryConfig :: standard ( ) ) 
162+                 . load ( ) 
163+                 . await ; 
164+             anyhow:: Ok ( Client :: new ( & config) ) 
165+         } ) 
166+         . await ?
167+         . clone ( ) ; 
168+     Ok ( client) 
169+ } 
170+ 
160171struct  ClientDrivenUpload  { 
161172    object_key :  ObjectKey , 
162173    upload_id :  UploadId , 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments