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
sourceimpl Builder
impl Builder
sourcepub fn region(self, region: impl Into<Option<Region>>) -> Self
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();
sourcepub fn set_region(&mut self, region: impl Into<Option<Region>>) -> &mut Self
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();
sourcepub fn endpoint_resolver(
self,
endpoint_resolver: impl ResolveAwsEndpoint + 'static
) -> Self
pub fn endpoint_resolver(
self,
endpoint_resolver: impl ResolveAwsEndpoint + 'static
) -> Self
Set the endpoint resolver to use when making requests
Examples
use std::sync::Arc;
use aws_types::SdkConfig;
use aws_smithy_http::endpoint::Endpoint;
use http::Uri;
let config = SdkConfig::builder().endpoint_resolver(
Endpoint::immutable(Uri::from_static("http://localhost:8080"))
).build();
sourcepub fn set_endpoint_resolver(
&mut self,
endpoint_resolver: Option<Arc<dyn ResolveAwsEndpoint>>
) -> &mut Self
pub fn set_endpoint_resolver(
&mut self,
endpoint_resolver: Option<Arc<dyn ResolveAwsEndpoint>>
) -> &mut Self
Set the endpoint resolver to use when making requests
Examples
use std::sync::Arc;
use aws_types::SdkConfig;
use aws_types::endpoint::ResolveAwsEndpoint;
fn endpoint_resolver_override() -> Option<Arc<dyn ResolveAwsEndpoint>> {
// ...
}
let mut config = SdkConfig::builder();
config.set_endpoint_resolver(endpoint_resolver_override());
config.build();
sourcepub fn retry_config(self, retry_config: RetryConfig) -> Self
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();
sourcepub fn set_retry_config(
&mut self,
retry_config: Option<RetryConfig>
) -> &mut Self
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);
let config = builder.build();
sourcepub fn timeout_config(self, timeout_config: Config) -> Self
pub fn timeout_config(self, timeout_config: Config) -> Self
Set the timeout::Config
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, tristate::TriState};
let api_timeout_config = timeout::Api::new()
.with_call_attempt_timeout(TriState::Set(Duration::from_secs(2)))
.with_call_timeout(TriState::Set(Duration::from_secs(5)));
let timeout_config = timeout::Config::new()
.with_api_timeouts(api_timeout_config);
let config = SdkConfig::builder().timeout_config(timeout_config).build();
sourcepub fn set_timeout_config(&mut self, timeout_config: Option<Config>) -> &mut Self
pub fn set_timeout_config(&mut self, timeout_config: Option<Config>) -> &mut Self
Set the timeout::Config
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, tristate::TriState};
fn set_preferred_timeouts(builder: &mut Builder) {
let api_timeout_config = timeout::Api::new()
.with_call_attempt_timeout(TriState::Set(Duration::from_secs(2)))
.with_call_timeout(TriState::Set(Duration::from_secs(5)));
let timeout_config = timeout::Config::new()
.with_api_timeouts(api_timeout_config);
builder.set_timeout_config(Some(timeout_config));
}
let mut builder = SdkConfig::builder();
set_preferred_timeouts(&mut builder);
let config = builder.build();
sourcepub fn sleep_impl(self, sleep_impl: Arc<dyn AsyncSleep>) -> Self
pub fn sleep_impl(self, sleep_impl: Arc<dyn AsyncSleep>) -> 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 std::sync::Arc;
use aws_smithy_async::rt::sleep::{AsyncSleep, 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 = Arc::new(ForeverSleep);
let config = SdkConfig::builder().sleep_impl(sleep_impl).build();
sourcepub fn set_sleep_impl(
&mut self,
sleep_impl: Option<Arc<dyn AsyncSleep>>
) -> &mut Self
pub fn set_sleep_impl(
&mut self,
sleep_impl: Option<Arc<dyn AsyncSleep>>
) -> &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 = std::sync::Arc::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();
sourcepub fn credentials_provider(self, provider: SharedCredentialsProvider) -> Self
pub fn credentials_provider(self, provider: SharedCredentialsProvider) -> Self
Set the credentials provider for the builder
Examples
use aws_types::credentials::{ProvideCredentials, SharedCredentialsProvider};
use aws_types::SdkConfig;
fn make_provider() -> impl ProvideCredentials {
// ...
}
let config = SdkConfig::builder()
.credentials_provider(SharedCredentialsProvider::new(make_provider()))
.build();
sourcepub fn set_credentials_provider(
&mut self,
provider: Option<SharedCredentialsProvider>
) -> &mut Self
pub fn set_credentials_provider(
&mut self,
provider: Option<SharedCredentialsProvider>
) -> &mut Self
Set the credentials provider for the builder
Examples
use aws_types::credentials::{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();
sourcepub fn app_name(self, app_name: AppName) -> Self
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.
sourcepub fn set_app_name(&mut self, app_name: Option<AppName>) -> &mut Self
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.
sourcepub fn http_connector(self, http_connector: HttpConnector) -> Self
pub fn http_connector(self, http_connector: HttpConnector) -> Self
Sets the HTTP connector that clients will use to make HTTP requests.
sourcepub fn set_http_connector(
&mut self,
http_connector: Option<HttpConnector>
) -> &mut Self
pub fn set_http_connector(
&mut self,
http_connector: Option<HttpConnector>
) -> &mut Self
Sets the HTTP connector that clients will use to make HTTP requests.