Module aws_types::credentials[][src]

Expand description

AWS SDK Credentials

Implementing your own credentials provider

While for many use cases, using a built in credentials provider is sufficient, you may want to implement your own credential provider.

With static credentials

Note: In general, you should prefer to use the credential providers that come with the AWS SDK to get credentials. It is NOT secure to hardcode credentials into your application. Only use this approach if you really know what you’re doing.

See Credentials::from_keys for an example on how to use static credentials.

With dynamically loaded credentials

If you are loading credentials dynamically, you can provide your own implementation of ProvideCredentials. Generally, this is best done by defining an inherent async fn on your structure, then calling that method directly from the trait implementation.

use aws_types::credentials::{CredentialsError, Credentials, ProvideCredentials, future, self};
struct SubprocessCredentialProvider;

async fn invoke_command(command: &str) -> String {
    // implementation elided...

/// Parse access key and secret from the first two lines of a string
fn parse_credentials(creds: &str) -> credentials::Result {
    let mut lines = creds.lines();
    let akid ="invalid credentials"))?;
    let secret ="invalid credentials"))?;
    Ok(Credentials::new(akid, secret, None, None, "CustomCommand"))

impl SubprocessCredentialProvider {
    async fn load_credentials(&self) -> credentials::Result {
        let creds = invoke_command("").await;

impl ProvideCredentials for SubprocessCredentialProvider {
    fn provide_credentials<'a>(&'a self) -> future::ProvideCredentials<'a> where Self: 'a {


Convenience ProvideCredentials struct that implements the ProvideCredentials trait.


AWS SDK Credentials

Credentials Provider wrapper that may be shared


Error returned when credentials failed to load.


Asynchronous Credentials Provider

Type Definitions

Result type for credential providers.