Skip to content

Commit b0b9d7a

Browse files
committed
Move out CDK example and update docs
1 parent 1127d6f commit b0b9d7a

17 files changed

Lines changed: 67 additions & 305 deletions

README.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
[![GitHub Actions](https://github.com/rnag/py-secrets-cache/actions/workflows/release.yml/badge.svg)](https://github.com/rnag/py-secrets-cache/actions/workflows/release.yml)
77
[![Documentation Status](https://readthedocs.org/projects/secrets-cache/badge/?version=latest)](https://secrets-cache.readthedocs.io/en/latest/?version=latest)
88

9+
> [!tip] Want a full AWS Lambda + CDK deployment example?
10+
> Check out [secrets-cache-cdk-example](https://github.com/rnag/secrets-cache-cdk-example)
11+
> for a ready-to-deploy Python CDK project that demonstrates `secrets-cache` usage
12+
> with Secrets Manager and SSM parameters, including caching timings.
13+
914
Cache secrets locally from AWS Secrets Manager and other secret stores, with optional local caching for development or Lambda-friendly usage.
1015

1116
* PyPI package: https://pypi.org/project/secrets-cache/
@@ -116,6 +121,68 @@ pip install secrets-cache[local]
116121

117122
This enables optional `~/.secrets_cache.toml` caching for local testing.
118123

124+
## AWS CDK Example
125+
126+
We’ve created a small **AWS CDK Python project** that demonstrates how to use `secrets-cache` in an AWS Lambda function.
127+
128+
**Repository:** [secrets-cache-cdk-example](https://github.com/rnag/secrets-cache-cdk-example)
129+
130+
This example shows:
131+
132+
* How to deploy a Lambda function using CDK that automatically installs `secrets-cache`.
133+
* How to fetch **Secrets Manager secrets** and **SSM parameters** from Lambda.
134+
* How module-level caching in `secrets-cache` speeds up repeated fetches in warm Lambda containers.
135+
* How to log fetch times in milliseconds to observe caching in action.
136+
137+
### Quickstart
138+
139+
1. Sign up for an [AWS account](https://aws.amazon.com/free/) (free tier is sufficient).
140+
2. Install the [AWS CLI](https://aws.amazon.com/cli/) and run:
141+
142+
```bash
143+
aws configure
144+
```
145+
146+
3. Install [Docker Desktop](https://www.docker.com/products/docker-desktop) (needed for CDK bundling).
147+
4. Clone the example repo:
148+
149+
```bash
150+
git clone https://github.com/rnag/secrets-cache-cdk-example
151+
cd secrets-cache-cdk-example
152+
```
153+
154+
5. Install dependencies and activate the virtual environment:
155+
156+
```bash
157+
python3 -m venv .venv
158+
source .venv/bin/activate
159+
pip install -r requirements.txt
160+
```
161+
162+
6. If this is your first CDK deployment in the account, bootstrap it:
163+
164+
```bash
165+
cdk bootstrap
166+
```
167+
168+
7. Deploy the stack:
169+
170+
```bash
171+
cdk deploy
172+
```
173+
174+
8. Invoke the Lambda and see **timings for secret/parameter fetches** in real time:
175+
176+
```bash
177+
aws lambda invoke \
178+
--function-name CdkExampleStack-TestLambda \
179+
--log-type Tail \
180+
--query 'LogResult' \
181+
--output text | base64 --decode
182+
```
183+
184+
Logs will show how fast the secret and parameter are fetched, demonstrating caching between warm starts.
185+
119186
## Credits
120187

121188
Created with [Cookiecutter](https://github.com/audreyfeldroy/cookiecutter) and the [rnag/cookiecutter-pypackage](https://github.com/rnag/cookiecutter-pypackage) template.

cdk-example/.gitignore

Lines changed: 0 additions & 22 deletions
This file was deleted.

cdk-example/README.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

cdk-example/__init__.py

Whitespace-only changes.

cdk-example/app.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

cdk-example/cdk.json

Lines changed: 0 additions & 99 deletions
This file was deleted.

cdk-example/cdk_example/__init__.py

Whitespace-only changes.

cdk-example/cdk_example/cdk_example_stack.py

Lines changed: 0 additions & 54 deletions
This file was deleted.

cdk-example/lambda/__init__.py

Whitespace-only changes.

cdk-example/lambda/lambda_function.py

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)