July 1, 2025
How to Protect CloudFront Distribution with AWS WAF

Securing your CloudFront distribution is a crucial step in defending web applications from common attacks. AWS Web Application Firewall (WAF) helps filter and monitor traffic, allowing you to control access to your application based on defined rules. Here’s how to apply AWS WAF to your CloudFront setup and get the most out of it.
Step 1: Create a Web ACL in AWS WAF
- Go to the WAF console and create a new Web ACL.
- Choose the region as Global for CloudFront.
- Name your Web ACL and define default action behavior (allow or block).
- Add rules:
- Start with AWS Managed Rule Groups for baseline protection.
- Add rate-based rules to limit abusive traffic from a single IP.
- Define custom rules as needed for your application’s logic.
- Start with AWS Managed Rule Groups for baseline protection.
Step 2: Associate the Web ACL with CloudFront
- In the Web ACL setup flow, choose to associate it with a CloudFront distribution.
- Select the distribution you want to protect.
- Complete the configuration and deploy the Web ACL.
Step 3: Monitor and Adjust
- Enable Logging
Turn on WAF logging to send request data to CloudWatch Logs or an S3 bucket. This helps you analyze traffic patterns and refine rules. - Use Count Mode for Testing
Deploy new rules in count mode first. This allows you to review matched traffic without blocking it, reducing false positives. - Regularly Review Rules
Update managed rule groups and review your custom logic to keep up with evolving threats and usage patterns.
A Note on DDoS Protection
While AWS WAF handles Layer 7 (application layer) threats, broader DDoS protection is handled by AWS Shield. Shield Standard is included automatically and offers baseline network-level defense. For more sensitive workloads, Shield Advanced offers additional features and response services.
Best Practices Recap
- Use managed rule groups for easy protection from known attack vectors
- Always test new rules in count mode before enforcing them
- Monitor logs and metrics regularly
- Limit rule scope with conditions like IP match, string match, and rate-based filters
- Review and adapt your rules as traffic and application behavior change
With a properly configured WAF in place, you gain a first line of defense that helps secure your CloudFront-backed application against a range of threats.