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

source

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

Sets the BehaviorVersion used to build SdkConfig.

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.

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;
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. You generally won’t need to change this unless you’re using an async runtime other than Tokio.

source

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.

source

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 Configs.

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

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

pub fn test_credentials(self) -> Self

Set test credentials for use when signing requests

source

pub fn token_provider(self, token_provider: impl ProvideToken + 'static) -> Self

Override the access token provider used to build SdkConfig.

§Examples

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

let config = aws_config::from_env()
    .token_provider(create_my_token_provider())
    .load()
    .await;
source

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 header that gets sent along with requests.

The app name is selected from an ordered list of sources:

  1. This override.
  2. The value of the AWS_SDK_UA_APP_ID environment variable.
  3. Profile files from the key sdk_ua_app_id

If none of those sources are set the value is None and it is not added to the user agent header.

§Examples
use aws_config::AppName;
let config = aws_config::from_env()
    .app_name(AppName::new("my-app-name").expect("valid app name"))
    .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};

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 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 request_min_compression_size_bytes(self, size: 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 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;
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 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.

§

impl<T> Instrument for T

§

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

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

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.
§

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

§

fn fg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the foreground set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like red() and green(), which have the same functionality but are pithier.

§Example

Set foreground color to white using fg():

use yansi::{Paint, Color};

painted.fg(Color::White);

Set foreground color to white using white().

use yansi::Paint;

painted.white();
§

fn primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color::Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color::Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color::Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color::White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color::BrightWhite].

§Example
println!("{}", value.bright_white());
§

fn bg(&self, value: Color) -> Painted<&T>

Returns a styled value derived from self with the background set to value.

This method should be used rarely. Instead, prefer to use color-specific builder methods like on_red() and on_green(), which have the same functionality but are pithier.

§Example

Set background color to red using fg():

use yansi::{Paint, Color};

painted.bg(Color::Red);

Set background color to red using on_red().

use yansi::Paint;

painted.on_red();
§

fn on_primary(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color::Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color::Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color::Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color::White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color::BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

fn attr(&self, value: Attribute) -> Painted<&T>

Enables the styling [Attribute] value.

This method should be used rarely. Instead, prefer to use attribute-specific builder methods like bold() and underline(), which have the same functionality but are pithier.

§Example

Make text bold using attr():

use yansi::{Paint, Attribute};

painted.attr(Attribute::Bold);

Make text bold using using bold().

use yansi::Paint;

painted.bold();
§

fn bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute::Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute::RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute::Strike].

§Example
println!("{}", value.strike());
§

fn quirk(&self, value: Quirk) -> Painted<&T>

Enables the yansi [Quirk] value.

This method should be used rarely. Instead, prefer to use quirk-specific builder methods like mask() and wrap(), which have the same functionality but are pithier.

§Example

Enable wrapping using .quirk():

use yansi::{Paint, Quirk};

painted.quirk(Quirk::Wrap);

Enable wrapping using wrap().

use yansi::Paint;

painted.wrap();
§

fn mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Linger].

§Example
println!("{}", value.linger());
§

fn clear(&self) -> Painted<&T>

👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear(). The clear() method will be removed in a future release.

Returns self with the quirk() set to [Quirk::Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk::OnBright].

§Example
println!("{}", value.on_bright());
§

fn whenever(&self, value: Condition) -> Painted<&T>

Conditionally enable styling based on whether the [Condition] value applies. Replaces any previous condition.

See the crate level docs for more details.

§Example

Enable styling painted only when both stdout and stderr are TTYs:

use yansi::{Paint, Condition};

painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
source§

impl<T> Same for T

§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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