使用 Rust Amazon SDK 获取 Secrets Manager 密钥值 - Amazon Secrets Manager
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

在应用程序中,您可以通过在任何 Amazon 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(()) }