logo
pub struct EnvironmentProvider { /* private fields */ }
Expand description

Provides AWS credentials from environment variables.

Available Environment Variables

  • AWS_ACCESS_KEY_ID:

    Access key ID

  • AWS_SECRET_ACCESS_KEY:

    Secret access key

  • AWS_SESSION_TOKEN:

    Session token

  • AWS_CREDENTIAL_EXPIRATION:

    Expiration time in RFC 3339 format (e.g. 1996-12-19T16:39:57-08:00). If unset, credentials won’t expire.

Example

use futures::future::Future;
use rusoto_credential::{EnvironmentProvider, ProvideAwsCredentials};
use std::env;

#[tokio::main]
async fn main() {
    env::set_var("AWS_ACCESS_KEY_ID", "ANTN35UAENTS5UIAEATD");
    env::set_var("AWS_SECRET_ACCESS_KEY", "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    env::set_var("AWS_SESSION_TOKEN", "DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir");

    let creds = EnvironmentProvider::default().credentials().await.unwrap();

    assert_eq!(creds.aws_access_key_id(), "ANTN35UAENTS5UIAEATD");
    assert_eq!(creds.aws_secret_access_key(), "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    assert_eq!(creds.token(), &Some("DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir".to_string()));
    assert!(creds.expires_at().is_none()); // doesn't expire

    env::set_var("AWS_CREDENTIAL_EXPIRATION", "2018-04-21T01:13:02Z");
    let creds = EnvironmentProvider::default().credentials().await.unwrap();
    assert_eq!(creds.expires_at().unwrap().to_rfc3339(), "2018-04-21T01:13:02+00:00");
}

Implementations

Create an EnvironmentProvider with a non-standard variable prefix.

use std::future::Future;
use rusoto_credential::{EnvironmentProvider, ProvideAwsCredentials};
use std::env;

#[tokio::main]
async fn main() -> () {
    env::set_var("MYAPP_ACCESS_KEY_ID", "ANTN35UAENTS5UIAEATD");
    env::set_var("MYAPP_SECRET_ACCESS_KEY", "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    env::set_var("MYAPP_SESSION_TOKEN", "DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir");

    let creds = EnvironmentProvider::with_prefix("MYAPP").credentials().await.unwrap();

    assert_eq!(creds.aws_access_key_id(), "ANTN35UAENTS5UIAEATD");
    assert_eq!(creds.aws_secret_access_key(), "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    assert_eq!(creds.token(), &Some("DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir".to_string()));
    assert!(creds.expires_at().is_none()); // doesn't expire

    env::set_var("MYAPP_CREDENTIAL_EXPIRATION", "2018-04-21T01:13:02Z");
    let creds = EnvironmentProvider::with_prefix("MYAPP").credentials().await.unwrap();
    assert_eq!(creds.expires_at().unwrap().to_rfc3339(), "2018-04-21T01:13:02+00:00");
}

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Produce a new AwsCredentials future.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

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