Struct aws_config::ConfigLoader
source · pub struct ConfigLoader { /* private fields */ }
Expand description
Load default sources for all configuration with override support
Load a cross-service SdkConfig
from the environment
This builder supports overriding individual components of the generated config. Overriding a component will skip the standard resolution chain from for that component. For example, if you override the region provider, even if that provider returns None, the default region provider chain will not be used.
Implementations§
source§impl ConfigLoader
impl ConfigLoader
sourcepub fn behavior_version(self, behavior_version: BehaviorVersion) -> Self
pub fn behavior_version(self, behavior_version: BehaviorVersion) -> Self
Sets the BehaviorVersion
used to build SdkConfig
.
sourcepub fn region(self, region: impl ProvideRegion + 'static) -> Self
pub fn region(self, region: impl ProvideRegion + 'static) -> Self
sourcepub fn retry_config(self, retry_config: RetryConfig) -> Self
pub fn retry_config(self, retry_config: RetryConfig) -> Self
sourcepub fn timeout_config(self, timeout_config: TimeoutConfig) -> Self
pub fn timeout_config(self, timeout_config: TimeoutConfig) -> Self
Override the timeout config used to build SdkConfig
.
This will be merged with timeouts coming from the timeout information provider, which
currently includes a default CONNECT
timeout of 3.1s
.
If you want to disable timeouts, use TimeoutConfig::disabled
. If you want to disable
a specific timeout, use TimeoutConfig::set_<type>(None)
.
Note: This only sets timeouts for calls to AWS services. Timeouts for the credentials provider chain are configured separately.
§Examples
use aws_config::timeout::TimeoutConfig;
let config = aws_config::from_env()
.timeout_config(
TimeoutConfig::builder()
.operation_timeout(Duration::from_secs(5))
.build()
)
.load()
.await;
sourcepub fn sleep_impl(self, sleep: impl AsyncSleep + 'static) -> Self
pub fn sleep_impl(self, sleep: impl AsyncSleep + 'static) -> Self
Override the sleep implementation for this ConfigLoader
.
The sleep implementation is used to create timeout futures. You generally won’t need to change this unless you’re using an async runtime other than Tokio.
sourcepub fn time_source(self, time_source: impl TimeSource + 'static) -> Self
pub fn time_source(self, time_source: impl TimeSource + 'static) -> Self
Set the time source used for tasks like signing requests.
You generally won’t need to change this unless you’re compiling for a target that can’t provide a default, such as WASM, or unless you’re writing a test against the client that needs a fixed time.
sourcepub fn http_client(self, http_client: impl HttpClient + 'static) -> Self
pub fn http_client(self, http_client: impl HttpClient + 'static) -> Self
Override the HttpClient
for this ConfigLoader
.
The HTTP client will be used for both AWS services and credentials providers.
If you wish to use a separate HTTP client for credentials providers when creating clients,
then override the HTTP client set with this function on the client-specific Config
s.
§Examples
#[cfg(feature = "client-hyper")]
use std::time::Duration;
use aws_smithy_runtime::client::http::hyper_014::HyperClientBuilder;
let tls_connector = hyper_rustls::HttpsConnectorBuilder::new()
.with_webpki_roots()
// NOTE: setting `https_only()` will not allow this connector to work with IMDS.
.https_only()
.enable_http1()
.enable_http2()
.build();
let hyper_client = HyperClientBuilder::new().build(tls_connector);
let sdk_config = aws_config::from_env()
.http_client(hyper_client)
.load()
.await;
sourcepub fn identity_cache(
self,
identity_cache: impl ResolveCachedIdentity + 'static
) -> Self
pub fn identity_cache( self, identity_cache: impl ResolveCachedIdentity + 'static ) -> Self
Override the identity cache used to build SdkConfig
.
The identity cache caches AWS credentials and SSO tokens. By default, a lazy cache is used that will load credentials upon first request, cache them, and then reload them during another request when they are close to expiring.
§Examples
Change a setting on the default lazy caching implementation:
use aws_config::identity::IdentityCache;
use std::time::Duration;
let config = aws_config::from_env()
.identity_cache(
IdentityCache::lazy()
// Change the load timeout to 10 seconds.
// Note: there are other timeouts that could trigger if the load timeout is too long.
.load_timeout(Duration::from_secs(10))
.build()
)
.load()
.await;
sourcepub fn credentials_provider(
self,
credentials_provider: impl ProvideCredentials + 'static
) -> Self
pub fn credentials_provider( self, credentials_provider: impl ProvideCredentials + 'static ) -> Self
sourcepub fn no_credentials(self) -> Self
pub fn no_credentials(self) -> Self
Don’t use credentials to sign requests.
Turning off signing with credentials is necessary in some cases, such as using anonymous auth for S3, calling operations in STS that don’t require a signature, or using token-based auth.
Note: For tests, e.g. with a service like DynamoDB Local, this is not what you
want. If credentials are disabled, requests cannot be signed. For these use cases, use
test_credentials
.
§Examples
Turn off credentials in order to call a service without signing:
let config = aws_config::from_env()
.no_credentials()
.load()
.await;
sourcepub fn test_credentials(self) -> Self
pub fn test_credentials(self) -> Self
Set test credentials for use when signing requests
sourcepub fn token_provider(self, token_provider: impl ProvideToken + 'static) -> Self
pub fn token_provider(self, token_provider: impl ProvideToken + 'static) -> Self
sourcepub fn app_name(self, app_name: AppName) -> Self
pub fn app_name(self, app_name: AppName) -> Self
Override the name of the app used to build SdkConfig
.
This optional name is used to identify the application in the user agent that gets sent along with requests.
§Examples
use aws_config::AppName;
let config = aws_config::from_env()
.app_name(AppName::new("my-app-name").expect("valid app name"))
.load().await;
sourcepub fn profile_files(self, profile_files: ProfileFiles) -> Self
pub fn profile_files(self, profile_files: ProfileFiles) -> Self
Provides the ability to programmatically override the profile files that get loaded by the SDK.
The Default
for ProfileFiles
includes the default SDK config and credential files located in
~/.aws/config
and ~/.aws/credentials
respectively.
Any number of config and credential files may be added to the ProfileFiles
file set, with the
only requirement being that there is at least one of each. Profile file locations will produce an
error if they don’t exist, but the default config/credentials files paths are exempt from this validation.
§Example: Using a custom profile file path
use aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider};
use aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind};
let profile_files = ProfileFiles::builder()
.with_file(ProfileFileKind::Credentials, "some/path/to/credentials-file")
.build();
let sdk_config = aws_config::from_env()
.profile_files(profile_files)
.load()
.await;
sourcepub fn profile_name(self, profile_name: impl Into<String>) -> Self
pub fn profile_name(self, profile_name: impl Into<String>) -> Self
Override the profile name used by configuration providers
Profile name is selected from an ordered list of sources:
- This override.
- The value of the
AWS_PROFILE
environment variable. default
Each AWS profile has a name. For example, in the file below, the profiles are named
dev
, prod
and staging
:
[dev]
ec2_metadata_service_endpoint = http://my-custom-endpoint:444
[staging]
ec2_metadata_service_endpoint = http://my-custom-endpoint:444
[prod]
ec2_metadata_service_endpoint = http://my-custom-endpoint:444
See Named profiles for more information about naming profiles.
§Example: Using a custom profile name
use aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider};
use aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind};
let sdk_config = aws_config::from_env()
.profile_name("prod")
.load()
.await;
sourcepub fn endpoint_url(self, endpoint_url: impl Into<String>) -> Self
pub fn endpoint_url(self, endpoint_url: impl Into<String>) -> Self
Override the endpoint URL used for all AWS services.
This method will override the endpoint URL used for all AWS services. This primarily
exists to set a static endpoint for tools like LocalStack
. When sending requests to
production AWS services, this method should only be used for service-specific behavior.
When this method is used, the Region
is only used for
signing; it is not used to route the request.
§Examples
Use a static endpoint for all services
let sdk_config = aws_config::from_env()
.endpoint_url("http://localhost:1234")
.load()
.await;
sourcepub fn use_fips(self, use_fips: bool) -> Self
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.
sourcepub fn use_dual_stack(self, use_dual_stack: bool) -> Self
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
sourcepub fn stalled_stream_protection(
self,
stalled_stream_protection_config: StalledStreamProtectionConfig
) -> Self
pub fn stalled_stream_protection( self, stalled_stream_protection_config: StalledStreamProtectionConfig ) -> Self
Override the StalledStreamProtectionConfig
used to build SdkConfig
.
This configures stalled stream protection. When enabled, download streams that stop (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: When an override is provided, the default implementation is replaced.
§Examples
use aws_config::stalled_stream_protection::StalledStreamProtectionConfig;
use std::time::Duration;
let config = aws_config::from_env()
.stalled_stream_protection(
StalledStreamProtectionConfig::enabled()
.grace_period(Duration::from_secs(1))
.build()
)
.load()
.await;
sourcepub async fn load(self) -> SdkConfig
pub async fn load(self) -> SdkConfig
Load the default configuration chain
If fields have been overridden during builder construction, the override values will be used.
Otherwise, the default values for each field will be provided.
NOTE: When an override is provided, the default implementation is not used as a fallback.
This means that if you provide a region provider that does not return a region, no region will
be set in the resulting SdkConfig
.