mz_aws_util/lib.rs
1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use aws_config::{BehaviorVersion, ConfigLoader};
11use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
12use aws_smithy_runtime_api::client::http::HttpClient;
13use hyper_tls::HttpsConnector;
14
15#[cfg(feature = "s3")]
16pub mod s3;
17#[cfg(feature = "s3")]
18pub mod s3_uploader;
19
20/// Creates an AWS SDK configuration loader with the defaults for the latest
21/// behavior version plus some Materialize-specific overrides.
22pub fn defaults() -> ConfigLoader {
23 // Use the SDK's latest behavior version. We already pin the crate versions,
24 // and CI puts version upgrades through rigorous testing, so we're happy to
25 // take the latest behavior version. We can adjust this in the future as
26 // necessary, if the AWS SDK ships a new behavior version that causes
27 // trouble.
28 let behavior_version = BehaviorVersion::latest();
29
30 // This is the only method allowed to call `aws_config::defaults`.
31 #[allow(clippy::disallowed_methods)]
32 let loader = aws_config::defaults(behavior_version);
33
34 // Install our custom HTTP client.
35 let loader = loader.http_client(http_client());
36
37 loader
38}
39
40/// Returns an HTTP client for use with the AWS SDK that is appropriately
41/// configured for Materialize.
42pub fn http_client() -> impl HttpClient {
43 // The default AWS HTTP client uses rustls, while our company policy is to
44 // use native TLS.
45 HyperClientBuilder::new().build(HttpsConnector::new())
46}