aws_sdk_timestreamwrite/
client.rs

1// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
2async fn resolve_endpoint(
3    client: &crate::Client,
4) -> ::std::result::Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_runtime_api::box_error::BoxError> {
5    let describe_endpoints = client.describe_endpoints().send().await?;
6    let endpoint = describe_endpoints.endpoints().first().unwrap();
7    let expiry = client.config().time_source().expect("checked when ep discovery was enabled").now()
8        + ::std::time::Duration::from_secs(endpoint.cache_period_in_minutes() as u64 * 60);
9    Ok((
10        ::aws_smithy_types::endpoint::Endpoint::builder()
11            .url(format!("https://{}", endpoint.address()))
12            .build(),
13        expiry,
14    ))
15}
16
17impl Client {
18    /// Enable endpoint discovery for this client
19    ///
20    /// This method MUST be called to construct a working client.
21    pub async fn with_endpoint_discovery_enabled(
22        self,
23    ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_runtime_api::box_error::BoxError> {
24        let handle = self.handle.clone();
25
26        // The original client without endpoint discover gets moved into the endpoint discovery
27        // resolver since calls to DescribeEndpoint without discovery need to be made.
28        let client_without_discovery = self;
29        let (resolver, reloader) = crate::endpoint_discovery::create_cache(
30            move || {
31                let client = client_without_discovery.clone();
32                async move { resolve_endpoint(&client).await }
33            },
34            handle
35                .conf
36                .sleep_impl()
37                .expect("endpoint discovery requires the client config to have a sleep impl"),
38            handle
39                .conf
40                .time_source()
41                .expect("endpoint discovery requires the client config to have a time source"),
42        )
43        .await?;
44
45        use ::aws_smithy_runtime_api::shared::IntoShared;
46        let mut conf = handle.conf.to_builder();
47        conf.set_endpoint_resolver(Some(resolver.into_shared()));
48
49        let client_with_discovery = crate::Client::from_conf(conf.build());
50        Ok((client_with_discovery, reloader))
51    }
52}
53
54#[derive(Debug)]
55pub(crate) struct Handle {
56    pub(crate) conf: crate::Config,
57    #[allow(dead_code)] // unused when a service does not provide any operations
58    pub(crate) runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
59}
60
61/// Client for Amazon Timestream Write
62///
63/// Client for invoking operations on Amazon Timestream Write. Each operation on Amazon Timestream Write is a method on this
64/// this struct. `.send()` MUST be invoked on the generated operations to dispatch the request to the service.
65/// ## Constructing a `Client`
66///
67/// A [`Config`] is required to construct a client. For most use cases, the [`aws-config`]
68/// crate should be used to automatically resolve this config using
69/// [`aws_config::load_from_env()`], since this will resolve an [`SdkConfig`] which can be shared
70/// across multiple different AWS SDK clients. This config resolution process can be customized
71/// by calling [`aws_config::from_env()`] instead, which returns a [`ConfigLoader`] that uses
72/// the [builder pattern] to customize the default config.
73///
74/// In the simplest case, creating a client looks as follows:
75/// ```rust,no_run
76/// # async fn wrapper() {
77/// let config = aws_config::load_from_env().await;
78/// // You MUST call `with_endpoint_discovery_enabled` to produce a working client for this service.
79/// let client = aws_sdk_timestreamwrite::Client::new(&config).with_endpoint_discovery_enabled().await;
80/// # }
81/// ```
82///
83/// Occasionally, SDKs may have additional service-specific values that can be set on the [`Config`] that
84/// is absent from [`SdkConfig`], or slightly different settings for a specific client may be desired.
85/// The [`Builder`](crate::config::Builder) struct implements `From<&SdkConfig>`, so setting these specific settings can be
86/// done as follows:
87///
88/// ```rust,no_run
89/// # async fn wrapper() {
90/// let sdk_config = ::aws_config::load_from_env().await;
91/// let config = aws_sdk_timestreamwrite::config::Builder::from(&sdk_config)
92/// # /*
93///     .some_service_specific_setting("value")
94/// # */
95///     .build();
96/// # }
97/// ```
98///
99/// See the [`aws-config` docs] and [`Config`] for more information on customizing configuration.
100///
101/// _Note:_ Client construction is expensive due to connection thread pool initialization, and should
102/// be done once at application start-up.
103///
104/// [`Config`]: crate::Config
105/// [`ConfigLoader`]: https://docs.rs/aws-config/*/aws_config/struct.ConfigLoader.html
106/// [`SdkConfig`]: https://docs.rs/aws-config/*/aws_config/struct.SdkConfig.html
107/// [`aws-config` docs]: https://docs.rs/aws-config/*
108/// [`aws-config`]: https://crates.io/crates/aws-config
109/// [`aws_config::from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.from_env.html
110/// [`aws_config::load_from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.load_from_env.html
111/// [builder pattern]: https://rust-lang.github.io/api-guidelines/type-safety.html#builders-enable-construction-of-complex-values-c-builder
112/// # Using the `Client`
113///
114/// A client has a function for every operation that can be performed by the service.
115/// For example, the [`CreateBatchLoadTask`](crate::operation::create_batch_load_task) operation has
116/// a [`Client::create_batch_load_task`], function which returns a builder for that operation.
117/// The fluent builder ultimately has a `send()` function that returns an async future that
118/// returns a result, as illustrated below:
119///
120/// ```rust,ignore
121/// let result = client.create_batch_load_task()
122///     .client_token("example")
123///     .send()
124///     .await;
125/// ```
126///
127/// The underlying HTTP requests that get made by this can be modified with the `customize_operation`
128/// function on the fluent builder. See the [`customize`](crate::client::customize) module for more
129/// information.
130#[derive(::std::clone::Clone, ::std::fmt::Debug)]
131pub struct Client {
132    handle: ::std::sync::Arc<Handle>,
133}
134
135impl Client {
136    /// Creates a new client from the service [`Config`](crate::Config).
137    ///
138    /// # Panics
139    ///
140    /// This method will panic in the following cases:
141    ///
142    /// - Retries or timeouts are enabled without a `sleep_impl` configured.
143    /// - Identity caching is enabled without a `sleep_impl` and `time_source` configured.
144    /// - No `behavior_version` is provided.
145    ///
146    /// The panic message for each of these will have instructions on how to resolve them.
147    #[track_caller]
148    pub fn from_conf(conf: crate::Config) -> Self {
149        let handle = Handle {
150            conf: conf.clone(),
151            runtime_plugins: crate::config::base_client_runtime_plugins(conf),
152        };
153        if let Err(err) = Self::validate_config(&handle) {
154            panic!("Invalid client configuration: {err}");
155        }
156        Self {
157            handle: ::std::sync::Arc::new(handle),
158        }
159    }
160
161    /// Returns the client's configuration.
162    pub fn config(&self) -> &crate::Config {
163        &self.handle.conf
164    }
165
166    fn validate_config(handle: &Handle) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
167        let mut cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
168        handle
169            .runtime_plugins
170            .apply_client_configuration(&mut cfg)?
171            .validate_base_client_config(&cfg)?;
172        Ok(())
173    }
174}
175
176impl Client {
177    /// Creates a new client from an [SDK Config](::aws_types::sdk_config::SdkConfig).
178    ///
179    /// # Panics
180    ///
181    /// - This method will panic if the `sdk_config` is missing an async sleep implementation. If you experience this panic, set
182    ///   the `sleep_impl` on the Config passed into this function to fix it.
183    /// - This method will panic if the `sdk_config` is missing an HTTP connector. If you experience this panic, set the
184    ///   `http_connector` on the Config passed into this function to fix it.
185    /// - 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.
186    #[track_caller]
187    pub fn new(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
188        Self::from_conf(sdk_config.into())
189    }
190}
191
192mod create_batch_load_task;
193
194mod create_database;
195
196mod create_table;
197
198/// Operation customization and supporting types.
199///
200/// The underlying HTTP requests made during an operation can be customized
201/// by calling the `customize()` method on the builder returned from a client
202/// operation call. For example, this can be used to add an additional HTTP header:
203///
204/// ```ignore
205/// # async fn wrapper() -> ::std::result::Result<(), aws_sdk_timestreamwrite::Error> {
206/// # let client: aws_sdk_timestreamwrite::Client = unimplemented!();
207/// use ::http::header::{HeaderName, HeaderValue};
208///
209/// let result = client.create_batch_load_task()
210///     .customize()
211///     .mutate_request(|req| {
212///         // Add `x-example-header` with value
213///         req.headers_mut()
214///             .insert(
215///                 HeaderName::from_static("x-example-header"),
216///                 HeaderValue::from_static("1"),
217///             );
218///     })
219///     .send()
220///     .await;
221/// # }
222/// ```
223pub mod customize;
224
225mod delete_database;
226
227mod delete_table;
228
229mod describe_batch_load_task;
230
231mod describe_database;
232
233mod describe_endpoints;
234
235mod describe_table;
236
237mod list_batch_load_tasks;
238
239mod list_databases;
240
241mod list_tables;
242
243mod list_tags_for_resource;
244
245mod resume_batch_load_task;
246
247mod tag_resource;
248
249mod untag_resource;
250
251mod update_database;
252
253mod update_table;
254
255mod write_records;