python-tf-cloudfront-lambda-s3.patterns.advancelocal.dev
python-tf-cloudfront-lambda-s3
A plain Python handler on a Lambda function URL from OpenTofu. CloudFront serves the page from S3, caches /api/live for 5 seconds, and lets /api/private through only with a caller key.
App
- Python 3.12 handler
Runs on
- CloudFront
- origin access control for S3 and Lambda
- CloudFront Function and KeyValueStore for the caller key
- response headers policy
- S3
- Lambda function URL, IAM auth, Python 3.12, deployed with OpenTofu
Foundation
- inf-baseline
- Wiz scanning
- Scheduled deploys and checks
Cache, live
Polling /api/live every second through CloudFront.
waiting for the first poll
CloudFront hittrip to the app
Caller key
/api/private needs an x-api-key header, which CloudFront checks before the request reaches the app. Without a valid key CloudFront answers 403.
curl -H 'x-api-key: <your key>' https://python-tf-cloudfront-lambda-s3.patterns.advancelocal.dev/api/private