Expand description

githubcrates-iodocs-rs


Retrieve AWS secrets and interact with Secrets Manager and SSM Parameter Store.


Usage

Note: this example requires the all feature to be enabled.

use aws_secrets::{config_from_env, SSMParamExt, SecretsExt};
use serde_json::{to_string, Value};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let shared_config = config_from_env().await;

    // Retrieve a secret from AWS Secrets Manager
    let secret_name = "my-secret";
    let value: Value = secret_name.get_secret(&shared_config).await?;
    let secret_string = to_string(&value)?;
    println!("[{secret_name}] Retrieved secret. value={secret_string}");

    // Retrieve a parameter from AWS SSM Parameter Store
    let param_name = "/my/secure/param";
    let value = param_name.get_secure_string(&shared_config).await?;
    println!("[{param_name}] Retrieved parameter. value={value:?}");

    Ok(())
}

Examples

You can check out sample usage of this crate in the examples/ folder in the project repo on GitHub.

Readme Docs

You can find the crate’s readme documentation on the crates.io page, or alternatively in the README.md file on the GitHub project repo.

Dependencies and Features

This library uses only the minimum required dependencies, in order to keep the overall size small. It leverages the AWS SDK for Rust for making calls to AWS APIs.

Note: Any desired features must be enabled individually, as no features are enabled by default.

Available features
  • all - Enables support for AWS Secrets Manager and SSM Parameter Store.
  • params - Enables support for AWS SSM Parameter Store.
  • sm - Enables support for AWS Secrets Manager.
Enabling Features

Update the project’s Cargo.toml to include any optional features to enable:

[dependencies]
aws-secrets = { version = "*", features = ["all"] }

Re-exports

pub use aws_config as config;

Enums

Library-specific errors

Traits

Trait for str types, enables interaction with AWS SSM Parameter Store.

Trait for str types, enables interaction with AWS Secrets Manager.

Functions

Load a default configuration from the environment

Type Definitions

A Result alias where the Err case is aws_secrets::Error.