使用 Rust AWS SDK 获取 Secrets Manager 密钥值 - AWS Secrets Manager

使用 Rust AWS SDK 获取 Secrets Manager 密钥值

在应用程序中,您可以通过在任何 AWS SDK 中调用 GetSecretValueBatchGetSecretValue 来检索密钥。不过,我们建议您通过使用客户端缓存来缓存您的密钥值。缓存密钥可以提高速度并降低成本。

对于 Rust 应用程序,请使用 Secrets Manager 基于 Rust 的缓存组件或直接使用 GetSecretValue 或 BatchGetSecretValue 调用 SDK

以下代码示例展示了如何获取 Secrets Manager 密钥值。

所需权限:secretsmanager:GetSecretValue

async fn show_secret(client: &Client, name: &str) -> Result<(), Error> { let resp = client.get_secret_value().secret_id(name).send().await?; println!("Value: {}", resp.secret_string().unwrap_or("No value!")); Ok(()) }