How to create aws_config object from profile?

Viewed 173

Does anyone know how to create aws_config in Rust from a profile file and not from environment. Most the examples use following to create aws_config

let shared_config = aws_config::from_env().region(region_provider).load().await;

In my case, the credential are dynamically created and stored at .aws/credentials. Can you please share a code snippet that demonstrate this feature?

Thanks

1 Answers

Based on the documentation, you want something like this:

let config = aws_config::from_env()
    .credentials_provider(
        aws_config::profile::ProfileFileCredentialsProvider::builder()
        // If you need a specific profile, uncomment this line:
        // .profile_name("profilename")
        .build()
    )
    .region(region_provider)
    .load()
    .await;

See ProfileFileCredentialsProvider.

Related