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

source

pub fn region(self, region: impl ProvideRegion + 'static) -> Self

Override the region used to build SdkConfig.

Examples
use aws_types::region::Region;
let config = aws_config::from_env()
    .region(Region::new("us-east-1"))
    .load().await;
source

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

Override the retry_config used to build SdkConfig.

Examples
use aws_config::retry::RetryConfig;

let config = aws_config::from_env()
    .retry_config(RetryConfig::standard().with_max_attempts(2))
    .load()
    .await;
source

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

Override the timeout config used to build SdkConfig. 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;
source

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.

source

pub fn http_connector(self, http_connector: impl Into<HttpConnector>) -> Self

Override the HttpConnector for this ConfigLoader. The connector will be used when sending operations. This does not set the HTTP connector used by config providers. To change that connector, use ConfigLoader::configure.

Examples
use std::time::Duration;
use aws_smithy_client::{Client, hyper_ext};
use aws_smithy_client::erase::DynConnector;
use aws_smithy_client::http_connector::ConnectorSettings;

let https_connector = hyper_rustls::HttpsConnectorBuilder::new()
    .with_webpki_roots()
    .https_only()
    .enable_http1()
    .enable_http2()
    .build();
let smithy_connector = hyper_ext::Adapter::builder()
    // Optionally set things like timeouts as well
    .connector_settings(
        ConnectorSettings::builder()
            .connect_timeout(Duration::from_secs(5))
            .build()
    )
    .build(https_connector);
let sdk_config = aws_config::from_env()
    .http_connector(smithy_connector)
    .load()
    .await;
source

pub fn credentials_cache(self, credentials_cache: CredentialsCache) -> Self

Override the credentials cache used to build SdkConfig.

Examples

Override the credentials cache but load the default value for region:

let config = aws_config::from_env()
    .credentials_cache(CredentialsCache::lazy())
    .load()
    .await;
source

pub fn credentials_provider( self, credentials_provider: impl ProvideCredentials + 'static ) -> Self

Override the credentials provider used to build SdkConfig.

Examples

Override the credentials provider but load the default value for region:

let config = aws_config::from_env()
    .credentials_provider(create_my_credential_provider())
    .load()
    .await;
source

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;
source

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:

  1. This override.
  2. The value of the AWS_PROFILE environment variable.
  3. 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;
source

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;
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 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 configure(self, provider_config: ProviderConfig) -> Self

Set configuration for all sub-loaders (credentials, region etc.)

Update the ProviderConfig used for all nested loaders. This can be used to override the HTTPs connector used by providers or to stub in an in memory Env or Fs for testing.

Examples
use aws_config::provider_config::ProviderConfig;
let custom_https_connector = hyper_rustls::HttpsConnectorBuilder::new()
    .with_webpki_roots()
    .https_only()
    .enable_http1()
    .build();
let provider_config = ProviderConfig::default().with_tcp_connector(custom_https_connector);
let shared_config = aws_config::from_env().configure(provider_config).load().await;
source

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

Trait Implementations§

source§

impl Debug for ConfigLoader

source§

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

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

impl Default for ConfigLoader

source§

fn default() -> ConfigLoader

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

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · 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 Twhere U: From<T>,

const: unstable · 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · 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