如何从配置文件创建 aws_config 对象?

smi*_*hra 5 amazon-s3 rust aws-sdk

有谁知道如何从配置文件而不是环境中创建 Rust 中的 aws_config 。大多数示例使用以下内容来创建 aws_config

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

就我而言,凭证是动态创建的并存储在 .aws/credentials 中。您能分享一段演示此功能的代码片段吗?

谢谢

cdh*_*wie 10

根据文档,您想要这样的东西:

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;
Run Code Online (Sandbox Code Playgroud)

ProfileFileCredentialsProvider