File tree 1 file changed +17
-6
lines changed
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> {
132
132
key_prefix : String ,
133
133
runtime : RT ,
134
134
) -> 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 ?;
141
136
let storage = Self {
142
137
client,
143
138
bucket,
@@ -157,6 +152,22 @@ impl<RT: Runtime> S3Storage<RT> {
157
152
}
158
153
}
159
154
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
+
160
171
struct ClientDrivenUpload {
161
172
object_key : ObjectKey ,
162
173
upload_id : UploadId ,
You can’t perform that action at this time.
0 commit comments