aws-sdk-timestreamwrite 1.98.0

AWS SDK for Amazon Timestream Write
Documentation
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
async fn resolve_endpoint(
    client: &crate::Client,
) -> ::std::result::Result<(::aws_smithy_types::endpoint::Endpoint, ::std::time::SystemTime), ::aws_smithy_runtime_api::box_error::BoxError> {
    let describe_endpoints = client.describe_endpoints().send().await?;
    let endpoint = describe_endpoints.endpoints().first().unwrap();
    let expiry = client.config().time_source().expect("checked when ep discovery was enabled").now()
        + ::std::time::Duration::from_secs(endpoint.cache_period_in_minutes() as u64 * 60);
    Ok((
        ::aws_smithy_types::endpoint::Endpoint::builder()
            .url(format!("https://{}", endpoint.address()))
            .build(),
        expiry,
    ))
}

impl Client {
    /// Enable endpoint discovery for this client
    ///
    /// This method MUST be called to construct a working client.
    pub async fn with_endpoint_discovery_enabled(
        self,
    ) -> ::std::result::Result<(Self, crate::endpoint_discovery::ReloadEndpoint), ::aws_smithy_runtime_api::box_error::BoxError> {
        let handle = self.handle.clone();

        // The original client without endpoint discover gets moved into the endpoint discovery
        // resolver since calls to DescribeEndpoint without discovery need to be made.
        let client_without_discovery = self;
        let (resolver, reloader) = crate::endpoint_discovery::create_cache(
            move || {
                let client = client_without_discovery.clone();
                async move { resolve_endpoint(&client).await }
            },
            handle
                .conf
                .sleep_impl()
                .expect("endpoint discovery requires the client config to have a sleep impl"),
            handle
                .conf
                .time_source()
                .expect("endpoint discovery requires the client config to have a time source"),
        )
        .await?;

        use ::aws_smithy_runtime_api::shared::IntoShared;
        let mut conf = handle.conf.to_builder();
        conf.set_endpoint_resolver(Some(resolver.into_shared()));

        let client_with_discovery = crate::Client::from_conf(conf.build());
        Ok((client_with_discovery, reloader))
    }
}

#[derive(Debug)]
pub(crate) struct Handle {
    pub(crate) conf: crate::Config,
    #[allow(dead_code)] // unused when a service does not provide any operations
    pub(crate) runtime_plugins: ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins,
}

/// Client for Amazon Timestream Write
///
/// Client for invoking operations on Amazon Timestream Write. Each operation on Amazon Timestream Write is a method on this
/// this struct. `.send()` MUST be invoked on the generated operations to dispatch the request to the service.
/// ## Constructing a `Client`
///
/// A [`Config`] is required to construct a client. For most use cases, the [`aws-config`]
/// crate should be used to automatically resolve this config using
/// [`aws_config::load_from_env()`], since this will resolve an [`SdkConfig`] which can be shared
/// across multiple different AWS SDK clients. This config resolution process can be customized
/// by calling [`aws_config::from_env()`] instead, which returns a [`ConfigLoader`] that uses
/// the [builder pattern] to customize the default config.
///
/// In the simplest case, creating a client looks as follows:
/// ```rust,no_run
/// # async fn wrapper() {
/// let config = aws_config::load_from_env().await;
/// // You MUST call `with_endpoint_discovery_enabled` to produce a working client for this service.
/// let client = aws_sdk_timestreamwrite::Client::new(&config).with_endpoint_discovery_enabled().await;
/// # }
/// ```
///
/// Occasionally, SDKs may have additional service-specific values that can be set on the [`Config`] that
/// is absent from [`SdkConfig`], or slightly different settings for a specific client may be desired.
/// The [`Builder`](crate::config::Builder) struct implements `From<&SdkConfig>`, so setting these specific settings can be
/// done as follows:
///
/// ```rust,no_run
/// # async fn wrapper() {
/// let sdk_config = ::aws_config::load_from_env().await;
/// let config = aws_sdk_timestreamwrite::config::Builder::from(&sdk_config)
/// # /*
///     .some_service_specific_setting("value")
/// # */
///     .build();
/// # }
/// ```
///
/// See the [`aws-config` docs] and [`Config`] for more information on customizing configuration.
///
/// _Note:_ Client construction is expensive due to connection thread pool initialization, and should
/// be done once at application start-up.
///
/// [`Config`]: crate::Config
/// [`ConfigLoader`]: https://docs.rs/aws-config/*/aws_config/struct.ConfigLoader.html
/// [`SdkConfig`]: https://docs.rs/aws-config/*/aws_config/struct.SdkConfig.html
/// [`aws-config` docs]: https://docs.rs/aws-config/*
/// [`aws-config`]: https://crates.io/crates/aws-config
/// [`aws_config::from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.from_env.html
/// [`aws_config::load_from_env()`]: https://docs.rs/aws-config/*/aws_config/fn.load_from_env.html
/// [builder pattern]: https://rust-lang.github.io/api-guidelines/type-safety.html#builders-enable-construction-of-complex-values-c-builder
/// # Using the `Client`
///
/// A client has a function for every operation that can be performed by the service.
/// For example, the [`CreateBatchLoadTask`](crate::operation::create_batch_load_task) operation has
/// a [`Client::create_batch_load_task`], function which returns a builder for that operation.
/// The fluent builder ultimately has a `send()` function that returns an async future that
/// returns a result, as illustrated below:
///
/// ```rust,ignore
/// let result = client.create_batch_load_task()
///     .client_token("example")
///     .send()
///     .await;
/// ```
///
/// The underlying HTTP requests that get made by this can be modified with the `customize_operation`
/// function on the fluent builder. See the [`customize`](crate::client::customize) module for more
/// information.
#[derive(::std::clone::Clone, ::std::fmt::Debug)]
pub struct Client {
    handle: ::std::sync::Arc<Handle>,
}

impl Client {
    /// Creates a new client from the service [`Config`](crate::Config).
    ///
    /// # Panics
    ///
    /// This method will panic in the following cases:
    ///
    /// - Retries or timeouts are enabled without a `sleep_impl` configured.
    /// - Identity caching is enabled without a `sleep_impl` and `time_source` configured.
    /// - No `behavior_version` is provided.
    ///
    /// The panic message for each of these will have instructions on how to resolve them.
    #[track_caller]
    pub fn from_conf(conf: crate::Config) -> Self {
        let handle = Handle {
            conf: conf.clone(),
            runtime_plugins: crate::config::base_client_runtime_plugins(conf),
        };
        if let Err(err) = Self::validate_config(&handle) {
            panic!("Invalid client configuration: {err}");
        }
        Self {
            handle: ::std::sync::Arc::new(handle),
        }
    }

    /// Returns the client's configuration.
    pub fn config(&self) -> &crate::Config {
        &self.handle.conf
    }

    fn validate_config(handle: &Handle) -> ::std::result::Result<(), ::aws_smithy_runtime_api::box_error::BoxError> {
        let mut cfg = ::aws_smithy_types::config_bag::ConfigBag::base();
        handle
            .runtime_plugins
            .apply_client_configuration(&mut cfg)?
            .validate_base_client_config(&cfg)?;
        Ok(())
    }
}

impl Client {
    /// Creates a new client from an [SDK Config](::aws_types::sdk_config::SdkConfig).
    ///
    /// # Panics
    ///
    /// - This method will panic if the `sdk_config` is missing an async sleep implementation. If you experience this panic, set
    ///   the `sleep_impl` on the Config passed into this function to fix it.
    /// - This method will panic if the `sdk_config` is missing an HTTP connector. If you experience this panic, set the
    ///   `http_connector` on the Config passed into this function to fix it.
    /// - 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.
    #[track_caller]
    pub fn new(sdk_config: &::aws_types::sdk_config::SdkConfig) -> Self {
        Self::from_conf(sdk_config.into())
    }
}

mod create_batch_load_task;

mod create_database;

mod create_table;

/// Operation customization and supporting types.
///
/// The underlying HTTP requests made during an operation can be customized
/// by calling the `customize()` method on the builder returned from a client
/// operation call. For example, this can be used to add an additional HTTP header:
///
/// ```ignore
/// # async fn wrapper() -> ::std::result::Result<(), aws_sdk_timestreamwrite::Error> {
/// # let client: aws_sdk_timestreamwrite::Client = unimplemented!();
/// use ::http_1x::header::{HeaderName, HeaderValue};
///
/// let result = client.create_batch_load_task()
///     .customize()
///     .mutate_request(|req| {
///         // Add `x-example-header` with value
///         req.headers_mut()
///             .insert(
///                 HeaderName::from_static("x-example-header"),
///                 HeaderValue::from_static("1"),
///             );
///     })
///     .send()
///     .await;
/// # }
/// ```
pub mod customize;

mod delete_database;

mod delete_table;

mod describe_batch_load_task;

mod describe_database;

mod describe_endpoints;

mod describe_table;

mod list_batch_load_tasks;

mod list_databases;

mod list_tables;

mod list_tags_for_resource;

mod resume_batch_load_task;

mod tag_resource;

mod untag_resource;

mod update_database;

mod update_table;

mod write_records;