Skip to content

Commit 2cac4d7

Browse files
rcohjdisanti
andauthored
Improve docs no credentials (#3279)
## Motivation and Context <!--- Why is this change required? What problem does it solve? --> <!--- If it fixes an open issue, please link to the issue here --> - aws-sdk-rust#971 ## Description Add documentation to `no_credentials` and add `test_credentials()` method ## Testing CI ## Checklist - [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --------- Co-authored-by: John DiSanti <jdisanti@amazon.com>
1 parent 9587dbc commit 2cac4d7

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

CHANGELOG.next.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,20 @@ result of the compilation."""
3232
references = ["aws-sdk-rust#975", "smithy-rs#3269"]
3333
meta = { "breaking" = false, "tada" = true, "bug" = false }
3434
author = "jdisanti"
35+
36+
[[aws-sdk-rust]]
37+
message = """Add `test_credentials` to `ConfigLoader` in `aws_config`. This allows the following pattern during tests:
38+
39+
```rust
40+
async fn main() {
41+
let conf = aws_config::defaults(BehaviorVersion::latest())
42+
.test_credentials()
43+
.await;
44+
}
45+
```
46+
47+
This is designed for unit tests and using local mocks like DynamoDB Local and LocalStack with the SDK.
48+
"""
49+
meta = { "breaking" = false, "tada" = true, "bug" = false }
50+
author = "rcoh"
51+
references = ["smithy-rs#3279", "aws-sdk-rust#971"]

aws/rust-runtime/aws-config/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ credentials-process = ["tokio/process"]
2020
default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"]
2121

2222
[dependencies]
23-
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types" }
23+
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
2424
aws-http = { path = "../../sdk/build/aws-sdk/sdk/aws-http" }
2525
aws-sdk-sts = { path = "../../sdk/build/aws-sdk/sdk/sts", default-features = false }
2626
aws-smithy-async = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-async" }
@@ -52,7 +52,6 @@ zeroize = { version = "1", optional = true }
5252
aws-sdk-ssooidc = { path = "../../sdk/build/aws-sdk/sdk/ssooidc", default-features = false, optional = true }
5353

5454
[dev-dependencies]
55-
aws-credential-types = { path = "../../sdk/build/aws-sdk/sdk/aws-credential-types", features = ["test-util"] }
5655
aws-smithy-runtime = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime", features = ["client", "connector-hyper-0-14-x", "test-util"] }
5756
aws-smithy-runtime-api = { path = "../../sdk/build/aws-sdk/sdk/aws-smithy-runtime-api", features = ["test-util"] }
5857
futures-util = { version = "0.3.16", default-features = false }

aws/rust-runtime/aws-config/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ mod loader {
212212
use crate::profile::profile_file::ProfileFiles;
213213
use crate::provider_config::ProviderConfig;
214214
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
215+
use aws_credential_types::Credentials;
215216
use aws_smithy_async::rt::sleep::{default_async_sleep, AsyncSleep, SharedAsyncSleep};
216217
use aws_smithy_async::time::{SharedTimeSource, TimeSource};
217218
use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
@@ -458,6 +459,10 @@ mod loader {
458459
/// anonymous auth for S3, calling operations in STS that don't require a signature,
459460
/// or using token-based auth.
460461
///
462+
/// **Note**: For tests, e.g. with a service like DynamoDB Local, this is **not** what you
463+
/// want. If credentials are disabled, requests cannot be signed. For these use cases, use
464+
/// [`test_credentials`](Self::test_credentials).
465+
///
461466
/// # Examples
462467
///
463468
/// Turn off credentials in order to call a service without signing:
@@ -474,6 +479,11 @@ mod loader {
474479
self
475480
}
476481

482+
/// Set test credentials for use when signing requests
483+
pub fn test_credentials(self) -> Self {
484+
self.credentials_provider(Credentials::for_tests())
485+
}
486+
477487
/// Override the name of the app used to build [`SdkConfig`](aws_types::SdkConfig).
478488
///
479489
/// This _optional_ name is used to identify the application in the user agent that

0 commit comments

Comments
 (0)