|
3 | 3 |  |
4 | 4 | [](https://secrets-cache.readthedocs.io/en/latest/?version=latest) |
5 | 5 |
|
6 | | -Cache secrets locally from AWS Secrets Manager and other secret stores. |
| 6 | +Cache secrets locally from AWS Secrets Manager and other secret stores, with optional local caching for development or Lambda-friendly usage. |
7 | 7 |
|
8 | 8 | * PyPI package: https://pypi.org/project/secrets-cache/ |
9 | 9 | * Free software: MIT License |
10 | 10 | * Documentation: https://secrets-cache.readthedocs.io. |
11 | 11 |
|
| 12 | +## Installation |
| 13 | + |
| 14 | +Install the base package (minimal, Lambda-friendly): |
| 15 | + |
| 16 | +```bash |
| 17 | +pip install secrets-cache[lambda] |
| 18 | +```` |
| 19 | + |
| 20 | +Install with **local cache support** (TOML) for testing / development: |
| 21 | + |
| 22 | +```bash |
| 23 | +pip install secrets-cache[local] |
| 24 | +``` |
| 25 | + |
| 26 | +Install with CLI support: |
| 27 | + |
| 28 | +```bash |
| 29 | +pip install secrets-cache[cli] |
| 30 | +``` |
| 31 | + |
| 32 | +You can also combine extras: |
| 33 | + |
| 34 | +```bash |
| 35 | +pip install "secrets-cache[local,cli]" |
| 36 | +``` |
| 37 | + |
| 38 | +## Usage |
| 39 | + |
| 40 | +```python |
| 41 | +from secrets_cache import get_secret, get_param |
| 42 | +
|
| 43 | +# Get a secret from AWS Secrets Manager |
| 44 | +my_secret = get_secret("my-secret-name", region="us-east-1") |
| 45 | +
|
| 46 | +# Get a parameter from AWS SSM Parameter Store |
| 47 | +my_param = get_param("/my/parameter/name", region="us-east-1") |
| 48 | +``` |
| 49 | + |
| 50 | +**Notes:** |
| 51 | + |
| 52 | +* By default, secrets are cached **in memory** to reduce repeated AWS calls. |
| 53 | +* If `local` extra is installed, secrets are also stored in `~/.secrets_cache.toml` for local caching. |
| 54 | +* Module-level caches persist across **warm AWS Lambda invocations**, so repeated calls in the same container are very fast. |
| 55 | + |
12 | 56 | ## Features |
13 | 57 |
|
14 | | -* TODO |
| 58 | +* Fetch secrets and parameters from AWS Secrets Manager / SSM. |
| 59 | +* Module-level caching for in-process efficiency. |
| 60 | +* Optional TOML caching for development. |
| 61 | +* Lambda-friendly usage without extra dependencies. |
| 62 | +* Easy to extend to other secret stores in the future. |
| 63 | + |
| 64 | +## Getting Started: AWS Lambda |
| 65 | + |
| 66 | +When running in AWS Lambda, you usually don’t want file-based caching. Use the `lambda` extra: |
| 67 | + |
| 68 | +```bash |
| 69 | +pip install secrets-cache[lambda] |
| 70 | +```` |
| 71 | +
|
| 72 | +### Example Lambda handler |
| 73 | +
|
| 74 | +```python |
| 75 | +import json |
| 76 | +from secrets_cache import get_secret, get_param |
| 77 | + |
| 78 | +def lambda_handler(event, context): |
| 79 | + # Get a secret from AWS Secrets Manager |
| 80 | + db_password = get_secret("my-db-password", region="us-east-1") |
| 81 | + |
| 82 | + # Get a parameter from AWS SSM Parameter Store |
| 83 | + api_key = get_param("/my/api/key", region="us-east-1") |
| 84 | + |
| 85 | + # Do something with your secrets |
| 86 | + return { |
| 87 | + "statusCode": 200, |
| 88 | + "body": json.dumps({ |
| 89 | + "db_password_length": len(db_password), |
| 90 | + "api_key_length": len(api_key) |
| 91 | + }) |
| 92 | + } |
| 93 | +``` |
| 94 | + |
| 95 | +### Notes for Lambda |
| 96 | + |
| 97 | +* **Module-level caching** ensures repeated calls in the same container are very fast. |
| 98 | +* No TOML or local file access is required — perfect for ephemeral Lambda environments. |
| 99 | +* Secrets are cached **in memory only**, and each new container start fetches them from AWS. |
| 100 | +* If you want local development caching, install the `local` extra: |
| 101 | + |
| 102 | +```bash |
| 103 | +pip install secrets-cache[local] |
| 104 | +``` |
| 105 | + |
| 106 | +This enables optional `~/.secrets_cache.toml` caching for local testing. |
15 | 107 |
|
16 | 108 | ## Credits |
17 | 109 |
|
18 | | -This package was created with [Cookiecutter](https://github.com/audreyfeldroy/cookiecutter) and the [rnag/cookiecutter-pypackage](https://github.com/rnag/cookiecutter-pypackage) project template. |
| 110 | +Created with [Cookiecutter](https://github.com/audreyfeldroy/cookiecutter) and the [rnag/cookiecutter-pypackage](https://github.com/rnag/cookiecutter-pypackage) template. |
0 commit comments