@@ -119,20 +119,47 @@ impl Builder {
119
119
String :: new ( )
120
120
} ;
121
121
122
- // Load config from environment, including:
122
+ // Config Loader will load config from environment.
123
+ //
124
+ // We will take user's input first if any. If there is no user input, we
125
+ // will fallback to the aws default load chain like the following:
126
+ //
123
127
// - Environment variables: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION
124
128
// - The default credentials files located in ~/.aws/config and ~/.aws/credentials (location can vary per platform)
125
129
// - Web Identity Token credentials from the environment or container (including EKS)
126
130
// - ECS Container Credentials (IAM roles for tasks)
127
131
// - EC2 Instance Metadata Service (IAM Roles attached to instance)
128
- let cfg = aws_config :: load_from_env ( ) . await ;
129
-
130
- let mut cfg = AwsS3 :: config :: Builder :: from ( & cfg ) ;
132
+ //
133
+ // Please keep in mind that the config loader only detect region and credentials.
134
+ let mut cfg_loader = aws_config :: ConfigLoader :: default ( ) ;
131
135
132
136
if let Some ( region) = & self . region {
133
- cfg = cfg. region ( AwsS3 :: Region :: new ( Cow :: from ( region. clone ( ) ) ) ) ;
137
+ cfg_loader = cfg_loader. region ( AwsS3 :: Region :: new ( Cow :: from ( region. clone ( ) ) ) ) ;
138
+ }
139
+
140
+ if let Some ( cred) = & self . credential {
141
+ match cred {
142
+ Credential :: HMAC {
143
+ access_key_id,
144
+ secret_access_key,
145
+ } => {
146
+ cfg_loader = cfg_loader. credentials_provider ( AwsS3 :: Credentials :: from_keys (
147
+ access_key_id,
148
+ secret_access_key,
149
+ None ,
150
+ ) ) ;
151
+ }
152
+ _ => {
153
+ return Err ( Error :: BackendConfigurationInvalid {
154
+ key : "credential" . to_string ( ) ,
155
+ value : "" . to_string ( ) ,
156
+ } ) ;
157
+ }
158
+ }
134
159
}
135
160
161
+ let mut cfg = AwsS3 :: config:: Builder :: from ( & cfg_loader. load ( ) . await ) ;
162
+
136
163
// Load users input first, if user not input, we will fallback to aws
137
164
// default load logic.
138
165
if let Some ( endpoint) = & self . endpoint {
@@ -170,29 +197,6 @@ impl Builder {
170
197
cfg = cfg. endpoint_resolver ( AwsS3 :: Endpoint :: immutable ( uri) ) ;
171
198
}
172
199
173
- // Load users input first, if user not input, we will fallback to aws
174
- // default load logic.
175
- if let Some ( cred) = & self . credential {
176
- match cred {
177
- Credential :: HMAC {
178
- access_key_id,
179
- secret_access_key,
180
- } => {
181
- cfg = cfg. credentials_provider ( AwsS3 :: Credentials :: from_keys (
182
- access_key_id,
183
- secret_access_key,
184
- None ,
185
- ) ) ;
186
- }
187
- _ => {
188
- return Err ( Error :: BackendConfigurationInvalid {
189
- key : "credential" . to_string ( ) ,
190
- value : "" . to_string ( ) ,
191
- } ) ;
192
- }
193
- }
194
- }
195
-
196
200
Ok ( Arc :: new ( Backend {
197
201
// Make `/` as the default of root.
198
202
root,
0 commit comments