aws_utils_secretsmanager
AWS Secrets Manager utilities for retrieving secret values from AWS Secrets Manager.
Features
- Simple interface for retrieving secrets from AWS Secrets Manager
- Support for secret versioning with version ID and version stage
- Custom error handling with detailed error types
- Support for custom AWS endpoints (useful for testing with LocalStack)
- Support for AWS SDK's default credential chain
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Basic Example
use ;
async
Using Custom Endpoint
use ;
async
Using Custom Timeout Configuration
use Duration;
use ;
async
Using with TimeoutConfig
use ;
use ;
use Duration;
async
Getting Raw Secret Output with Versioning
use ;
async
Getting Latest Secret Version
use ;
async
API Reference
Functions
make_client_with_timeout_default(endpoint_url: Option<String>) -> Client
Creates an AWS Secrets Manager client with default timeout configuration.
endpoint_url: Optional custom endpoint URL for testing (e.g., LocalStack)- Returns: Configured AWS Secrets Manager Client with default timeouts
- Default timeouts:
- Connect timeout: 3100 seconds
- Operation timeout: 60 seconds
- Operation attempt timeout: 55 seconds
- Read timeout: 50 seconds
make_client_with_timeout(endpoint_url: Option<String>, connect_timeout: Option<Duration>, operation_timeout: Option<Duration>, operation_attempt_timeout: Option<Duration>, read_timeout: Option<Duration>) -> Client
Creates an AWS Secrets Manager client with custom timeout configuration.
endpoint_url: Optional custom endpoint URL for testing (e.g., LocalStack)connect_timeout: Optional timeout for establishing connectionsoperation_timeout: Optional timeout for entire operationsoperation_attempt_timeout: Optional timeout for individual operation attemptsread_timeout: Optional timeout for reading responses- Returns: Configured AWS Secrets Manager Client with custom timeouts
make_client(endpoint_url: Option<String>, timeout_config: Option<TimeoutConfig>) -> Client
Creates an AWS Secrets Manager client with optional custom endpoint URL and timeout configuration.
endpoint_url: Optional custom endpoint URL for testing (e.g., LocalStack)timeout_config: Optional timeout configuration- Returns: Configured AWS Secrets Manager Client
get_secret_value(client: &Client, secret_id: &str) -> Result<String, Error>
Retrieves a secret value as a string from the current version.
client: AWS Secrets Manager clientsecret_id: Secret identifier (name or ARN)- Returns: Secret value as String
get_secret_value_raw(client: &Client, secret_id: Option<impl Into<String>>, version_id: Option<impl Into<String>>, version_stage: Option<impl Into<String>>) -> Result<GetSecretValueOutput, Error>
Retrieves raw secret output from AWS Secrets Manager with version control.
client: AWS Secrets Manager clientsecret_id: Optional secret identifier (name or ARN)version_id: Optional version UUID to retrieve specific versionversion_stage: Optional version stage (e.g., "AWSCURRENT", "AWSPENDING")- Returns: Raw GetSecretValueOutput from AWS SDK
Error Types
The crate defines custom error types:
Error::BuildError: AWS SDK build errorsError::AwsSdk: AWS SDK service errorsError::ValidationError: Validation errorsError::NotFound: Secret not found
Secret Versioning
AWS Secrets Manager supports versioning of secrets. You can:
- Get the current version using
"AWSCURRENT"stage - Get the pending version using
"AWSPENDING"stage - Get a specific version using the version UUID
- Let AWS choose the version by omitting version parameters
Version Stages
AWSCURRENT: The current version of the secretAWSPENDING: The version that will become current after rotation completes- Custom stages: You can define custom version stages for your workflow
Testing
Set up your test environment:
# Optional: Custom Secrets Manager endpoint (e.g., LocalStack)
# Run tests
Test Commands
# Run all tests
# Run with logging
RUST_LOG=info
# Run specific test
Authentication
The client uses the AWS SDK's default credential chain for authentication:
- Environment variables (
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY,AWS_REGION) - ECS task role (for Fargate/ECS)
- EC2 instance profile
- AWS credentials file
- Other configured credential providers
Use Cases
Database Credentials
use ;
use Value;
async
API Keys
use ;
async
License
MIT