aws_sdk_s3/
client.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2#[derive(Debug)]
3pub(crate) struct Handle {
4    pub(crate) conf: crate::Config,
5    #[allow(dead_code)] // unused when a service does not provide any operations
6    pub(crate) runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
7}
8
9/// Client for Amazon Simple Storage Service
10///
11/// Client for invoking operations on Amazon Simple Storage Service. Each operation on Amazon Simple Storage Service is a method on this
12/// this struct. `.send()` MUST be invoked on the generated operations to dispatch the request to the service.
13/// ## Constructing a `Client`
14///
15/// A [`Config`] is required to construct a client. For most use cases, the [`aws-config`]
16/// crate should be used to automatically resolve this config using
17/// [`aws_config::load_from_env()`], since this will resolve an [`SdkConfig`] which can be shared
18/// across multiple different AWS SDK clients. This config resolution process can be customized
19/// by calling [`aws_config::from_env()`] instead, which returns a [`ConfigLoader`] that uses
20/// the [builder pattern] to customize the default config.
21///
22/// In the simplest case, creating a client looks as follows:
23/// ```rust,no_run
24/// # async fn wrapper() {
25/// let config = aws_config::load_from_env().await;
26/// let client = aws_sdk_s3::Client::new(&config);
27/// # }
28/// ```
29///
30/// Occasionally, SDKs may have additional service-specific values that can be set on the [`Config`] that
31/// is absent from [`SdkConfig`], or slightly different settings for a specific client may be desired.
32/// The [`Config`] struct implements `From<&SdkConfig>`, so setting these specific settings can be
33/// done as follows:
34///
35/// ```rust,no_run
36/// # async fn wrapper() {
37/// let sdk_config = ::aws_config::load_from_env().await;
38/// let config = aws_sdk_s3::config::Builder::from(&sdk_config)
39/// # /*
40///     .some_service_specific_setting("value")
41/// # */
42///     .build();
43/// # }
44/// ```
45///
46/// See the [`aws-config` docs] and [`Config`] for more information on customizing configuration.
47///
48/// _Note:_ Client construction is expensive due to connection thread pool initialization, and should
49/// be done once at application start-up.
50///
51/// [`Config`]: crate::Config
52/// [`ConfigLoader`]: https://docs.rs/aws-config/*/aws_config/struct.ConfigLoader.html
53/// [`SdkConfig`]: https://docs.rs/aws-config/*/aws_config/struct.SdkConfig.html
54/// [`aws-config` docs]: https://docs.rs/aws-config/*
55/// [`aws-config`]: https://crates.io/crates/aws-config
56/// [`aws_config::from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.from_env.html
57/// [`aws_config::load_from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.load_from_env.html
58/// [builder pattern]: https://rust-lang.github.io/api-guidelines/type-safety.html#builders-enable-construction-of-complex-values-c-builder
59/// # Using the `Client`
60///
61/// A client has a function for every operation that can be performed by the service.
62/// For example, the [`AbortMultipartUpload`](crate::operation::abort_multipart_upload) operation has
63/// a [`Client::abort_multipart_upload`], function which returns a builder for that operation.
64/// The fluent builder ultimately has a `send()` function that returns an async future that
65/// returns a result, as illustrated below:
66///
67/// ```rust,ignore
68/// let result = client.abort_multipart_upload()
69///     .bucket("example")
70///     .send()
71///     .await;
72/// ```
73///
74/// The underlying HTTP requests that get made by this can be modified with the `customize_operation`
75/// function on the fluent builder. See the [`customize`](crate::client::customize) module for more
76/// information.
77#[derive(::std::clone::Clone, ::std::fmt::Debug)]
78pub struct Client {
79    handle: ::std::sync::Arc<Handle>,
80}
81
82impl Client {
83    /// Creates a new client from the service [`Config`](crate::Config).
84    ///
85    /// # Panics
86    ///
87    /// This method will panic in the following cases:
88    ///
89    /// - Retries or timeouts are enabled without a `sleep_impl` configured.
90    /// - Identity caching is enabled without a `sleep_impl` and `time_source` configured.
91    /// - No `behavior_version` is provided.
92    ///
93    /// The panic message for each of these will have instructions on how to resolve them.
94    #[track_caller]
95    pub fn from_conf(conf: crate::Config) -> Self {
96        let handle = Handle {
97            conf: conf.clone(),
98            runtime_plugins: crate::config::base_client_runtime_plugins(conf),
99        };
100        if let Err(err) = Self::validate_config(&handle) {
101            panic!("Invalid client configuration: {err}");
102        }
103        Self {
104            handle: ::std::sync::Arc::new(handle),
105        }
106    }
107
108    /// Returns the client's configuration.
109    pub fn config(&self) -> &crate::Config {
110        &self.handle.conf
111    }
112
113    fn validate_config(handle: &Handle) -> Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
114        let mut cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
115        handle
116            .runtime_plugins
117            .apply_client_configuration(&mut cfg)?
118            .validate_base_client_config(&cfg)?;
119        Ok(())
120    }
121}
122
123impl Client {
124    /// Creates a new client from an [SDK Config](::aws_types::sdk_config::SdkConfig).
125    ///
126    /// # Panics
127    ///
128    /// - This method will panic if the `sdk_config` is missing an async sleep implementation. If you experience this panic, set
129    ///     the `sleep_impl` on the Config passed into this function to fix it.
130    /// - This method will panic if the `sdk_config` is missing an HTTP connector. If you experience this panic, set the
131    ///     `http_connector` on the Config passed into this function to fix it.
132    /// - This method will panic if no `BehaviorVersion` is provided. If you experience this panic, set `behavior_version` on the Config or enable the `behavior-version-latest` Cargo feature.
133    #[track_caller]
134    pub fn new(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
135        Self::from_conf(sdk_config.into())
136    }
137}
138
139mod abort_multipart_upload;
140
141mod complete_multipart_upload;
142
143mod copy_object;
144
145mod create_bucket;
146
147mod create_multipart_upload;
148
149mod create_session;
150
151/// Operation customization and supporting types.
152///
153/// The underlying HTTP requests made during an operation can be customized
154/// by calling the `customize()` method on the builder returned from a client
155/// operation call. For example, this can be used to add an additional HTTP header:
156///
157/// ```ignore
158/// # async fn wrapper() -> ::std::result::Result<(), aws_sdk_s3::Error> {
159/// # let client: aws_sdk_s3::Client = unimplemented!();
160/// use ::http::header::{HeaderName, HeaderValue};
161///
162/// let result = client.abort_multipart_upload()
163///     .customize()
164///     .mutate_request(|req| {
165///         // Add `x-example-header` with value
166///         req.headers_mut()
167///             .insert(
168///                 HeaderName::from_static("x-example-header"),
169///                 HeaderValue::from_static("1"),
170///             );
171///     })
172///     .send()
173///     .await;
174/// # }
175/// ```
176pub mod customize;
177
178mod delete_bucket;
179
180mod delete_bucket_analytics_configuration;
181
182mod delete_bucket_cors;
183
184mod delete_bucket_encryption;
185
186mod delete_bucket_intelligent_tiering_configuration;
187
188mod delete_bucket_inventory_configuration;
189
190mod delete_bucket_lifecycle;
191
192mod delete_bucket_metrics_configuration;
193
194mod delete_bucket_ownership_controls;
195
196mod delete_bucket_policy;
197
198mod delete_bucket_replication;
199
200mod delete_bucket_tagging;
201
202mod delete_bucket_website;
203
204mod delete_object;
205
206mod delete_object_tagging;
207
208mod delete_objects;
209
210mod delete_public_access_block;
211
212mod get_bucket_accelerate_configuration;
213
214mod get_bucket_acl;
215
216mod get_bucket_analytics_configuration;
217
218mod get_bucket_cors;
219
220mod get_bucket_encryption;
221
222mod get_bucket_intelligent_tiering_configuration;
223
224mod get_bucket_inventory_configuration;
225
226mod get_bucket_lifecycle_configuration;
227
228mod get_bucket_location;
229
230mod get_bucket_logging;
231
232mod get_bucket_metrics_configuration;
233
234mod get_bucket_notification_configuration;
235
236mod get_bucket_ownership_controls;
237
238mod get_bucket_policy;
239
240mod get_bucket_policy_status;
241
242mod get_bucket_replication;
243
244mod get_bucket_request_payment;
245
246mod get_bucket_tagging;
247
248mod get_bucket_versioning;
249
250mod get_bucket_website;
251
252mod get_object;
253
254mod get_object_acl;
255
256mod get_object_attributes;
257
258mod get_object_legal_hold;
259
260mod get_object_lock_configuration;
261
262mod get_object_retention;
263
264mod get_object_tagging;
265
266mod get_object_torrent;
267
268mod get_public_access_block;
269
270mod head_bucket;
271
272mod head_object;
273
274mod list_bucket_analytics_configurations;
275
276mod list_bucket_intelligent_tiering_configurations;
277
278mod list_bucket_inventory_configurations;
279
280mod list_bucket_metrics_configurations;
281
282mod list_buckets;
283
284mod list_directory_buckets;
285
286mod list_multipart_uploads;
287
288mod list_object_versions;
289
290mod list_objects;
291
292mod list_objects_v2;
293
294mod list_parts;
295
296mod put_bucket_accelerate_configuration;
297
298mod put_bucket_acl;
299
300mod put_bucket_analytics_configuration;
301
302mod put_bucket_cors;
303
304mod put_bucket_encryption;
305
306mod put_bucket_intelligent_tiering_configuration;
307
308mod put_bucket_inventory_configuration;
309
310mod put_bucket_lifecycle_configuration;
311
312mod put_bucket_logging;
313
314mod put_bucket_metrics_configuration;
315
316mod put_bucket_notification_configuration;
317
318mod put_bucket_ownership_controls;
319
320mod put_bucket_policy;
321
322mod put_bucket_replication;
323
324mod put_bucket_request_payment;
325
326mod put_bucket_tagging;
327
328mod put_bucket_versioning;
329
330mod put_bucket_website;
331
332mod put_object;
333
334mod put_object_acl;
335
336mod put_object_legal_hold;
337
338mod put_object_lock_configuration;
339
340mod put_object_retention;
341
342mod put_object_tagging;
343
344mod put_public_access_block;
345
346mod restore_object;
347
348mod select_object_content;
349
350mod upload_part;
351
352mod upload_part_copy;
353
354mod write_get_object_response;