Struct aws_types::sdk_config::Builder

source ·
pub struct Builder { /* private fields */ }
Expand description

Builder for AWS Shared Configuration

Important: Using the aws-config crate to configure the SDK is preferred to invoking this builder directly. Using this builder directly won’t pull in any AWS recommended default configuration values.

Implementations§

source§

impl Builder

source

pub fn region(self, region: impl Into<Option<Region>>) -> Self

Set the region for the builder

§Examples
use aws_types::SdkConfig;
use aws_types::region::Region;
let config = SdkConfig::builder().region(Region::new("us-east-1")).build();
source

pub fn set_region(&mut self, region: impl Into<Option<Region>>) -> &mut Self

Set the region for the builder

§Examples
fn region_override() -> Option<Region> {
    // ...
}
use aws_types::SdkConfig;
use aws_types::region::Region;
let mut builder = SdkConfig::builder();
if let Some(region) = region_override() {
    builder.set_region(region);
}
let config = builder.build();
source

pub fn endpoint_url(self, endpoint_url: impl Into<String>) -> Self

Set the endpoint URL to use when making requests.

§Examples
use aws_types::SdkConfig;
let config = SdkConfig::builder().endpoint_url("http://localhost:8080").build();
source

pub fn set_endpoint_url(&mut self, endpoint_url: Option<String>) -> &mut Self

Set the endpoint URL to use when making requests.

source

pub fn retry_config(self, retry_config: RetryConfig) -> Self

Set the retry_config for the builder

Note: Retries require a sleep implementation in order to work. When enabling retry, make sure to set one with Self::sleep_impl or Self::set_sleep_impl.

§Examples
use aws_types::SdkConfig;
use aws_smithy_types::retry::RetryConfig;

let retry_config = RetryConfig::standard().with_max_attempts(5);
let config = SdkConfig::builder().retry_config(retry_config).build();
source

pub fn set_retry_config( &mut self, retry_config: Option<RetryConfig>, ) -> &mut Self

Set the retry_config for the builder

Note: Retries require a sleep implementation in order to work. When enabling retry, make sure to set one with Self::sleep_impl or Self::set_sleep_impl.

§Examples
use aws_types::sdk_config::{SdkConfig, Builder};
use aws_smithy_types::retry::RetryConfig;

fn disable_retries(builder: &mut Builder) {
    let retry_config = RetryConfig::standard().with_max_attempts(1);
    builder.set_retry_config(Some(retry_config));
}

let mut builder = SdkConfig::builder();
disable_retries(&mut builder);
source

pub fn timeout_config(self, timeout_config: TimeoutConfig) -> Self

Set the TimeoutConfig for the builder

Note: Timeouts require a sleep implementation in order to work. When enabling timeouts, be sure to set one with Self::sleep_impl or Self::set_sleep_impl.

§Examples
use aws_types::SdkConfig;
use aws_smithy_types::timeout::TimeoutConfig;

let timeout_config = TimeoutConfig::builder()
    .operation_attempt_timeout(Duration::from_secs(2))
    .operation_timeout(Duration::from_secs(5))
    .build();
let config = SdkConfig::builder()
    .timeout_config(timeout_config)
    .build();
source

pub fn set_timeout_config( &mut self, timeout_config: Option<TimeoutConfig>, ) -> &mut Self

Set the TimeoutConfig for the builder

Note: Timeouts require a sleep implementation in order to work. When enabling timeouts, be sure to set one with Self::sleep_impl or Self::set_sleep_impl.

§Examples
use aws_types::sdk_config::{SdkConfig, Builder};
use aws_smithy_types::timeout::TimeoutConfig;

fn set_preferred_timeouts(builder: &mut Builder) {
    let timeout_config = TimeoutConfig::builder()
        .operation_attempt_timeout(Duration::from_secs(2))
        .operation_timeout(Duration::from_secs(5))
        .build();
    builder.set_timeout_config(Some(timeout_config));
}

let mut builder = SdkConfig::builder();
set_preferred_timeouts(&mut builder);
let config = builder.build();
source

pub fn sleep_impl(self, sleep_impl: impl AsyncSleep + 'static) -> Self

Set the sleep implementation for the builder.

The sleep implementation is used to create timeout futures.

Note: If you’re using the Tokio runtime, a TokioSleep implementation is available in the aws-smithy-async crate.

§Examples
use aws_smithy_async::rt::sleep::{AsyncSleep, SharedAsyncSleep, Sleep};
use aws_types::SdkConfig;

#[derive(Debug)]
pub struct ForeverSleep;

impl AsyncSleep for ForeverSleep {
    fn sleep(&self, duration: std::time::Duration) -> Sleep {
        Sleep::new(std::future::pending())
    }
}

let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
let config = SdkConfig::builder().sleep_impl(sleep_impl).build();
source

pub fn set_sleep_impl( &mut self, sleep_impl: Option<SharedAsyncSleep>, ) -> &mut Self

Set the sleep implementation for the builder. The sleep implementation is used to create timeout futures.

Note: If you’re using the Tokio runtime, a TokioSleep implementation is available in the aws-smithy-async crate.

§Examples
#[derive(Debug)]
pub struct ForeverSleep;

impl AsyncSleep for ForeverSleep {
    fn sleep(&self, duration: std::time::Duration) -> Sleep {
        Sleep::new(std::future::pending())
    }
}

fn set_never_ending_sleep_impl(builder: &mut Builder) {
    let sleep_impl = SharedAsyncSleep::new(ForeverSleep);
    builder.set_sleep_impl(Some(sleep_impl));
}

let mut builder = SdkConfig::builder();
set_never_ending_sleep_impl(&mut builder);
let config = builder.build();
source

pub fn identity_cache(self, cache: impl ResolveCachedIdentity + 'static) -> Self

Set the identity cache for caching credentials and SSO tokens.

The default identity cache will wait until the first request that requires authentication to load an identity. Once the identity is loaded, it is cached until shortly before it expires.

§Examples

Disabling identity caching:

use aws_smithy_runtime::client::identity::IdentityCache;
let config = SdkConfig::builder()
    .identity_cache(IdentityCache::no_cache())
    .build();

Changing settings on the default cache implementation:

use aws_smithy_runtime::client::identity::IdentityCache;
use std::time::Duration;

let config = SdkConfig::builder()
    .identity_cache(
        IdentityCache::lazy()
            .load_timeout(Duration::from_secs(10))
            .build()
    )
    .build();
source

pub fn set_identity_cache( &mut self, cache: Option<SharedIdentityCache>, ) -> &mut Self

Set the identity cache for caching credentials and SSO tokens.

The default identity cache will wait until the first request that requires authentication to load an identity. Once the identity is loaded, it is cached until shortly before it expires.

§Examples
use aws_smithy_runtime::client::identity::IdentityCache;

fn override_identity_cache() -> bool {
  // ...
}

let mut builder = SdkConfig::builder();
if override_identity_cache() {
    builder.set_identity_cache(Some(IdentityCache::lazy().build()));
}
let config = builder.build();
source

pub fn credentials_provider(self, provider: SharedCredentialsProvider) -> Self

Set the credentials provider for the builder

§Examples
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
use aws_types::SdkConfig;
fn make_provider() -> impl ProvideCredentials {
  // ...
}

let config = SdkConfig::builder()
    .credentials_provider(SharedCredentialsProvider::new(make_provider()))
    .build();
source

pub fn set_credentials_provider( &mut self, provider: Option<SharedCredentialsProvider>, ) -> &mut Self

Set the credentials provider for the builder

§Examples
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
use aws_types::SdkConfig;
fn make_provider() -> impl ProvideCredentials {
  // ...
}

fn override_provider() -> bool {
  // ...
}

let mut builder = SdkConfig::builder();
if override_provider() {
    builder.set_credentials_provider(Some(SharedCredentialsProvider::new(make_provider())));
}
let config = builder.build();
source

pub fn token_provider(self, provider: SharedTokenProvider) -> Self

Set the bearer auth token provider for the builder

§Examples
use aws_credential_types::provider::token::{ProvideToken, SharedTokenProvider};
use aws_types::SdkConfig;

fn make_provider() -> impl ProvideToken {
  // ...
}

let config = SdkConfig::builder()
    .token_provider(SharedTokenProvider::new(make_provider()))
    .build();
source

pub fn set_token_provider( &mut self, provider: Option<SharedTokenProvider>, ) -> &mut Self

Set the bearer auth token provider for the builder

§Examples
use aws_credential_types::provider::token::{ProvideToken, SharedTokenProvider};
use aws_types::SdkConfig;

fn make_provider() -> impl ProvideToken {
  // ...
}

fn override_provider() -> bool {
  // ...
}

let mut builder = SdkConfig::builder();
if override_provider() {
    builder.set_token_provider(Some(SharedTokenProvider::new(make_provider())));
}
let config = builder.build();
source

pub fn app_name(self, app_name: AppName) -> Self

Sets the name of the app that is using the client.

This optional name is used to identify the application in the user agent that gets sent along with requests.

source

pub fn set_app_name(&mut self, app_name: Option<AppName>) -> &mut Self

Sets the name of the app that is using the client.

This optional name is used to identify the application in the user agent that gets sent along with requests.

source

pub fn http_client(self, http_client: impl HttpClient + 'static) -> Self

Sets the HTTP client to use when making requests.

§Examples
use aws_types::sdk_config::{SdkConfig, TimeoutConfig};
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
use std::time::Duration;

// Create a connector that will be used to establish TLS connections
let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
    .with_webpki_roots()
    .https_only()
    .enable_http1()
    .enable_http2()
    .build();
// Create a HTTP client that uses the TLS connector. This client is
// responsible for creating and caching a HttpConnector when given HttpConnectorSettings.
// This hyper client will create HttpConnectors backed by hyper and the tls_connector.
let http_client = HyperClientBuilder::new().build(tls_connector);
let sdk_config = SdkConfig::builder()
    .http_client(http_client)
    // Connect/read timeouts are passed to the HTTP client when servicing a request
    .timeout_config(
        TimeoutConfig::builder()
            .connect_timeout(Duration::from_secs(5))
            .build()
    )
    .build();
source

pub fn set_http_client( &mut self, http_client: Option<SharedHttpClient>, ) -> &mut Self

Sets the HTTP client to use when making requests.

§Examples
use aws_types::sdk_config::{Builder, SdkConfig, TimeoutConfig};
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
use std::time::Duration;

fn override_http_client(builder: &mut Builder) {
    // Create a connector that will be used to establish TLS connections
    let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
        .with_webpki_roots()
        .https_only()
        .enable_http1()
        .enable_http2()
        .build();
    // Create a HTTP client that uses the TLS connector. This client is
    // responsible for creating and caching a HttpConnector when given HttpConnectorSettings.
    // This hyper client will create HttpConnectors backed by hyper and the tls_connector.
    let http_client = HyperClientBuilder::new().build(tls_connector);

    builder.set_http_client(Some(http_client));
}

let mut builder = SdkConfig::builder();
override_http_client(&mut builder);
let config = builder.build();
source

pub fn use_fips(self, use_fips: bool) -> Self

When true, send this request to the FIPS-compliant regional endpoint.

If no FIPS-compliant endpoint can be determined, dispatching the request will return an error.

source

pub fn set_use_fips(&mut self, use_fips: Option<bool>) -> &mut Self

When true, send this request to the FIPS-compliant regional endpoint.

If no FIPS-compliant endpoint can be determined, dispatching the request will return an error.

source

pub fn use_dual_stack(self, use_dual_stack: bool) -> Self

When true, send this request to the dual-stack endpoint.

If no dual-stack endpoint is available the request MAY return an error.

Note: Some services do not offer dual-stack as a configurable parameter (e.g. Code Catalyst). For these services, this setting has no effect

source

pub fn set_use_dual_stack(&mut self, use_dual_stack: Option<bool>) -> &mut Self

When true, send this request to the dual-stack endpoint.

If no dual-stack endpoint is available the request MAY return an error.

Note: Some services do not offer dual-stack as a configurable parameter (e.g. Code Catalyst). For these services, this setting has no effect

source

pub fn time_source(self, time_source: impl TimeSource + 'static) -> Self

The time source use to use for this client.

This only needs to be required for creating deterministic tests or platforms where SystemTime::now() is not supported.

source

pub fn set_time_source( &mut self, time_source: Option<SharedTimeSource>, ) -> &mut Self

The time source use to use for this client.

This only needs to be required for creating deterministic tests or platforms where SystemTime::now() is not supported.

source

pub fn disable_request_compression( self, disable_request_compression: bool, ) -> Self

When true, disable request compression. Defaults to false.

Only some services support request compression. For services that don’t support request compression, this setting does nothing.

source

pub fn set_disable_request_compression( &mut self, disable_request_compression: Option<bool>, ) -> &mut Self

When true, disable request compression. Defaults to false.

Only some services support request compression. For services that don’t support request compression, this setting does nothing.

source

pub fn request_min_compression_size_bytes( self, request_min_compression_size_bytes: u32, ) -> Self

The minimum size of request that should be compressed. Defaults to 10240 bytes.

When a request body’s size is lower than this, request compression will be skipped. This is useful for request bodies because, for small request bodies, compression may actually increase their size.

Only some services support request compression. For services that don’t support request compression, this setting does nothing.

source

pub fn set_request_min_compression_size_bytes( &mut self, request_min_compression_size_bytes: Option<u32>, ) -> &mut Self

The minimum size of request that should be compressed. Defaults to 10240 bytes.

When a request body’s size is lower than this, request compression will be skipped. This is useful for request bodies because, for small request bodies, compression may actually increase their size.

Only some services support request compression. For services that don’t support request compression, this setting does nothing.

source

pub fn behavior_version(self, behavior_version: BehaviorVersion) -> Self

Sets the BehaviorVersion for the SdkConfig

source

pub fn set_behavior_version( &mut self, behavior_version: Option<BehaviorVersion>, ) -> &mut Self

Sets the BehaviorVersion for the SdkConfig

source

pub fn service_config( self, service_config: impl LoadServiceConfig + 'static, ) -> Self

Sets the service config provider for the SdkConfig.

This provider is used when creating a service-specific config from an SdkConfig and provides access to config defined in the environment which would otherwise be inaccessible.

source

pub fn set_service_config( &mut self, service_config: Option<impl LoadServiceConfig + 'static>, ) -> &mut Self

Sets the service config provider for the SdkConfig.

This provider is used when creating a service-specific config from an SdkConfig and provides access to config defined in the environment which would otherwise be inaccessible.

source

pub fn insert_origin(&mut self, setting: &'static str, origin: Origin)

Set the origin of a setting.

This is used internally to understand how to merge config structs while respecting precedence of origins.

source

pub fn build(self) -> SdkConfig

Build a SdkConfig from this builder.

source§

impl Builder

source

pub fn stalled_stream_protection( self, stalled_stream_protection_config: StalledStreamProtectionConfig, ) -> Self

Set the StalledStreamProtectionConfig to configure protection for stalled streams.

This configures stalled stream protection. When enabled, download streams that stall (stream no data) for longer than a configured grace period will return an error.

Note: Stalled stream protection requires both a sleep implementation and a time source in order to work. When enabling stalled stream protection, make sure to set

§Examples
use std::time::Duration;
use aws_types::SdkConfig;
pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;

let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
    .grace_period(Duration::from_secs(1))
    .build();
let config = SdkConfig::builder()
    .stalled_stream_protection(stalled_stream_protection_config)
    .build();
source

pub fn set_stalled_stream_protection( &mut self, stalled_stream_protection_config: Option<StalledStreamProtectionConfig>, ) -> &mut Self

Set the StalledStreamProtectionConfig to configure protection for stalled streams.

This configures stalled stream protection. When enabled, download streams that stall (stream no data) for longer than a configured grace period will return an error.

By default, streams that transmit less than one byte per-second for five seconds will be cancelled.

Note: Stalled stream protection requires both a sleep implementation and a time source in order to work. When enabling stalled stream protection, make sure to set

§Examples
use std::time::Duration;
use aws_types::sdk_config::{SdkConfig, Builder};
pub use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;

fn set_stalled_stream_protection(builder: &mut Builder) {
    let stalled_stream_protection_config = StalledStreamProtectionConfig::enabled()
        .grace_period(Duration::from_secs(1))
        .build();
    builder.set_stalled_stream_protection(Some(stalled_stream_protection_config));
}

let mut builder = SdkConfig::builder();
set_stalled_stream_protection(&mut builder);
let config = builder.build();

Trait Implementations§

source§

impl Debug for Builder

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Builder

source§

fn default() -> Builder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more