aws_utils_ssm
AWS SSM utilities for getting parameter values from AWS Systems Manager Parameter Store.
Features
- Simple interface for retrieving SSM parameters
- Support for encrypted parameters with automatic decryption
- 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
Getting Raw Parameter Output
use ;
async
Using Custom Timeout Configuration
use Duration;
use ;
async
Using with TimeoutConfig
use ;
use ;
use Duration;
async
Logging AWS Communication
make_client accepts an optional [SharedInterceptor]. By passing an interceptor that
implements aws_sdk_ssm::config::Intercept, you can run custom logic — such as logging —
every time the client communicates with AWS.
The interceptor below logs each request, response, and operation result. It uses the
tracing crate, which is also what the AWS SDK uses
internally.
use make_client;
use ;
type BoxError = ;
;
# async
tracing does not emit anything until a subscriber is initialized. Set one up once in your
application (for example with tracing-subscriber) and control verbosity with RUST_LOG:
// Add `tracing-subscriber` to your dependencies.
fmt
.with_env_filter
.init;
Example output (RUST_LOG=info):
INFO SsmLoggingInterceptor: SSM -> AWS request method=POST uri=https://ssm.ap-northeast-1.amazonaws.com/
INFO SsmLoggingInterceptor: AWS -> SSM response status=200
INFO SsmLoggingInterceptor: SSM operation succeeded
API Reference
Functions
make_client_with_timeout_default(endpoint_url: Option<String>) -> Client
Creates an AWS SSM client with default timeout configuration.
endpoint_url: Optional custom endpoint URL for testing (e.g., LocalStack)- Returns: Configured AWS SSM 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 SSM 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 SSM Client with custom timeouts
make_client(endpoint_url: Option<String>, timeout_config: Option<TimeoutConfig>, interceptor: Option<SharedInterceptor>) -> Client
Creates an AWS SSM client with optional custom endpoint URL, timeout configuration, and interceptor.
endpoint_url: Optional custom endpoint URL for testing (e.g., LocalStack)timeout_config: Optional timeout configurationinterceptor: Optional interceptor for running custom logic (e.g. logging) on every AWS communication- Returns: Configured AWS SSM Client
get_parameter(client: &Client, name: &str) -> Result<String, Error>
Retrieves a parameter value as a string with automatic decryption.
client: AWS SSM clientname: Parameter name (e.g., "/my/parameter/name")- Returns: Parameter value as String
get_parameter_raw(client: &Client, name: Option<impl Into<String>>, with_decryption: Option<bool>) -> Result<GetParameterOutput, Error>
Retrieves raw parameter output from AWS SSM.
client: AWS SSM clientname: Optional parameter namewith_decryption: Whether to decrypt the parameter value- Returns: Raw GetParameterOutput 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: Parameter not found
Testing
The crate includes tests that require specific environment variables:
# Required for tests to run
# Optional: Custom SSM endpoint (e.g., LocalStack)
# Optional: Test parameter name (defaults to "/test/parameter")
# 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
License
MIT