Securely serve private content globally using AWS CloudFront + Lambda Function URLs β without managing any servers.
This project demonstrates how to proxy and cache content from any third-party S3-compatible object storage (e.g., MinIO, Wasabi, Backblaze, Yotta) using:
- π οΈ AWS Lambda for credentialed access to private buckets
- β‘ CloudFront as a global CDN with long-term edge caching
- π§° boto3 for S3-compatible API integration
- π No EC2, NGINX, or load balancers required!
- Replace EC2-based proxies with a fully serverless, zero-maintenance solution
- Safely expose private assets to the public via secure intermediaries
- Seamlessly integrate with custom websites or frontend apps
CloudFront β Lambda Function URL β Authenticated S3-Compatible Bucket
-
CloudFront receives a request like:
https://<distribution>.cloudfront.net/images/banner.webp -
It forwards the request to your Lambda Function URL
-
Lambda uses boto3 and stored credentials to fetch the image object securely from a private S3-compatible store
-
It returns the image with proper headers (e.g.,
Cache-Control,Content-Type) -
CloudFront caches and serves the response globally π
-
Create a Lambda function (Python 3.12+)
-
Add environment variables:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYS3_ENDPOINT_URLS3_BUCKET_NAME
-
Copy code from
lambda/lambda_function.py -
Enable Function URL with
Auth type = NONE
- Create a CloudFront distribution
- Set origin domain to your Lambda URL (without
https://) - Use HTTPS only for the origin protocol policy
- Add behavior for path pattern
/images/*(or as needed)
https://your-distribution.cloudfront.net/images/sample.img
- Use environment variables or AWS Secrets Manager for credentials
- Optionally implement:
- Header-based access checks in Lambda
- Signed URLs
- Origin Access Control (OAC) in CloudFront
- β Add image transformation (resize/compress) on-the-fly
- β Support for Signed CDN URLs
- β CloudFormation/Terraform IaC templates
- β Logging and analytics via CloudWatch
π Medium Post β βHow I Built a Serverless CDN for S3-Compatible Storage Using Lambda and CloudFrontβ
This project is licensed under the MIT License. See LICENSE for details.
Built with βοΈ AWS, π Python, and a passion for clean architecture.