AWS Secrets Manager Rust Caching Client
This crate provides a client for in-process caching of secrets from AWS Secrets Manager for Rust applications. It's heavily inspired by the AWS Secrets Manager Go Caching Client and the AWS SDK for Rust.
The client internally uses an LRU (least-recently used) caching scheme that provides O(1) insertions and O(1) lookups for cached values.
Getting started
To use this client you must have:
- A Rust development environment
- An Amazon Web Services (AWS) account to access secrets stored in AWS Secrets Manager and use AWS SDK for Rust.
Usage
The following sample demonstrates how to get started using the client:
use Client;
use SecretCache;
async
Forcing cache refreshes
If a secret has been rotated since the last value was fetched and cached, and hasn't expired in the cache, it's necessary to force a cache refresh for the value by calling AWS and updating the value.
This can be done with force_refresh(), for example:
match cache
.get_secret_string
.force_refresh
.send
.await
Cache Configuration
max_cache_size usizeThe maximum number of secrets to maintain in the cache before evicting the least frequently accessedcache_item_ttl u128The number of nanoseconds a cached secret will be considered valid before the secret value requires a refresh. Refreshing happens synchronously.
use Client;
use ;
use time;
async
Global Caching
Certain cloud environments like AWS Lambda encourage initializing clients in the global scope to avoid initialization for
each function invocation. This can be achieved using the lazy_static crate, for example:
use AsyncOnce;
use Client;
use SecretCache;
use lazy_static;
use Mutex;
// store the cache in the global scope - useful for runtime environments like AWS Lambda
lazy_static!
async
Development
Linting
The project uses rustfmt and clippy for
formatting and linting. Follow the instructions to install rustfmt and clippy and run:
Tests
Run unit tests locally with:
License
Licensed under the Apache License, Version 2.0 or the MIT license, at your option. Files in the project may not be copied, modified, or distributed except according to those terms.