#secrets-manager #aws-lambda #secret #lambda #aws #cache

aws-parameters-and-secrets-lambda

Cache AWS Secrets Manager secrets in your AWS Lambda function

2 releases (1 stable)

1.0.0 Mar 25, 2024
0.1.0 Jan 6, 2023

#120 in Caching

Download history 18/week @ 2024-07-22 7/week @ 2024-07-29 9/week @ 2024-08-12 10/week @ 2024-08-19 15/week @ 2024-09-09 2/week @ 2024-09-23 15/week @ 2024-09-30 80/week @ 2024-10-07 62/week @ 2024-10-14 66/week @ 2024-10-21 24/week @ 2024-10-28 77/week @ 2024-11-04

232 downloads per month

Apache-2.0 OR MIT

36KB
642 lines

aws-parameters-and-secrets-lambda

Cache AWS Secrets Manager secrets in your AWS Lambda function, reducing latency (we don't need to query another service) and cost (Secrets Manager charges based on queries).

Quickstart (Secrets)

Add the AWS Parameters and Secrets Lambda Extension layer to your Lambda function. Only version 2 of this layer is currently supported.

Assuming a secret exists with the name "backend-server" containing a key/value pair with a key of "api_key" and a value of "dd96eeda-16d3-4c86-975f-4986e603ec8c" (our super secret API key to our backend), this code will get the secret from the cache, querying Secrets Manager if it is not in the cache, and present it in a strongly-typed BackendServer object.

use aws_parameters_and_secrets_lambda::Manager;
use serde::Deserialize;

#[derive(Deserialize)]
struct BackendServer {
    api_key: String
}

let manager = Manager::default();
let secret = manager.get_secret("backend-server");
let secret_value: BackendServer = secret.get_typed().await?;
assert_eq!("dd96eeda-16d3-4c86-975f-4986e603ec8c", secret_value.api_key);

Documentation

Thorough documentation for this crate is available on docs.rs.

License

This crate is licensed under the MIT or Apache 2.0 license, at your option.

Dependencies

~6–21MB
~319K SLoC