2 Answers
- Newest
- Most votes
- Most comments
1
You are thinking in the right track. Better to have CloudFront as the entry point, to enable caching and global distribution of your content. Attach WAF to CloudFront so that all requests are screened before reaching your Lambda function, and depending on your needs, you can use a standard origin (e.g., S3, EC2) or Lambda@Edge for custom processing.
See here for more details. https://aws.amazon.com/developer/application-security-performance/articles/cost-optimization/
1
My recommendation is not to use custom lambda code acting as WAF, as WAF is more comprehensive and right service to protect resources.
answered 2 years ago
Alright, thanks a lot! We're proceeding with the WAF in front :)
Relevant content
asked 4 years ago
- AWS OFFICIALUpdated 6 months ago
- AWS OFFICIALUpdated a year ago

Hello,
I don't know if I was clear enough, but in the scenario I was talking about the Lambda itself works as WAF (calls the WAF internally and decides if the request goes to origin or gets blocked).
Same question: would the lambda use the optimization logics (and therefore could be skipped unless configured accordingly)? And should we also manage invocation limits and stuff? Would in the end that be cost effective if we set up a way to get all the requests to the lambda?
Thanks a lot
But by the way, you answered...it's like we thought. Better having the WAF in front of the CDN. That can also screen the CDN from attacks (resulting in cost optimization as well).