diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fb9213af12..1d3cad3a75 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -32,3 +32,20 @@ result of the compilation.""" references = ["aws-sdk-rust#975", "smithy-rs#3269"] meta = { "breaking" = false, "tada" = true, "bug" = false } author = "jdisanti" + +[[aws-sdk-rust]] +message = """Add `test_credentials` to `ConfigLoader` in `aws_config`. This allows the following pattern during tests: + +```rust +async fn main() { + let conf = aws_config::defaults(BehaviorVersion::latest()) + .test_credentials() + .await; +} +``` + +This is designed for unit tests and using local mocks like DynamoDB Local and LocalStack with the SDK. +""" +meta = { "breaking" = false, "tada" = true, "bug" = false } +author = "rcoh" +references = ["smithy-rs#3279", "aws-sdk-rust#971"] diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index 4c51dbaa40..627a00fd1c 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -20,7 +20,7 @@ credentials-process = ["tokio/process"] default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"] [dependencies] -aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types" } +aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http" } aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sdk/sts", default-features = false } aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async" } @@ -52,7 +52,6 @@ zeroize = { version = "1", optional = true } aws-sdk-ssooidc = { path = "../../sdk/build/aws-sdk/sdk/ssooidc", default-features = false, optional = true } [dev-dependencies] -aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] } aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x", "test-util"] } aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"] } futures-util = { version = "0.3.16", default-features = false } diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 5fb0f5592c..3feb455382 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -212,6 +212,7 @@ mod loader { use crate::profile::profile_file::ProfileFiles; use crate::provider_config::ProviderConfig; use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider}; + use aws_credential_types::Credentials; use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep}; use aws_smithy_async::time::{SharedTimeSource, TimeSource}; use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion; @@ -458,6 +459,10 @@ mod loader { /// 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`](Self::test_credentials). + /// /// # Examples /// /// Turn off credentials in order to call a service without signing: @@ -474,6 +479,11 @@ mod loader { self } + /// Set test credentials for use when signing requests + pub fn test_credentials(self) -> Self { + self.credentials_provider(Credentials::for_tests()) + } + /// Override the name of the app used to build [`SdkConfig`](aws_types::SdkConfig). /// /// This _optional_ name is used to identify the application in the user agent that