Blocking an IP address
Where to block a client IP address on AWS - network ACLs, security groups, firewall software, an ALB or NLB, AWS WAF IP sets and CloudFront geo restriction - and why a NACL stops helping behind CloudFront.
The available layers
Start with a client reaching a public EC2 instance directly, then add each layer:
- Instance only.
- The network ACL of the subnet can deny the IP: NACLs have deny rules.
- The security group can't: it only has allow rules. It can allow-list a known set of IPs, but not block one.
- Optional firewall software on the instance can also block it (costs CPU).
- With an ALB. The ALB terminates the connection, so the instances (now private, with an SG allowing only the ALB's SG) only see the ALB. Block the IP with the NACL of the ALB's subnets. The client's IP is in the
X-Forwarded-Forheader for the app. - With an NLB. Traffic passes through with the client IP preserved. Block with the NACL; NLBs also support security groups now.
- ALB + AWS WAF. Attach a web ACL to the ALB with an IP set rule (and rate-based or geo rules). WAF costs a little but filters at layer 7 with much more flexibility.
- CloudFront + WAF. With CloudFront in front, the ALB sees CloudFront's IPs, so a NACL can't block the client: it's not helpful here. Instead:
- attach WAF to the CloudFront distribution with an IP set rule;
- use CloudFront geo restriction to block whole countries;
- let the ALB security group allow only CloudFront (the AWS-managed prefix list for CloudFront origin-facing IPs).
Updated since the slides
CloudFront VPC origins let the ALB, NLB or EC2 instances sit in private subnets with no public entry at all, so CloudFront (with WAF) becomes the only way in. See CloudFront VPC origins.
Real-world examples
- A ticket site blocks a scraper's IP range with a WAF IP set on its CloudFront distribution and adds a rate-based rule of 2,000 requests per 5 minutes per IP.
Exam tips
- "Block a specific IP address at the subnet level" → NACL deny rule.
- "Security groups can deny an IP" → false: SGs only allow.
- "Block IPs with CloudFront in front" → WAF on CloudFront (IP set); NACLs only see CloudFront IPs.
- "Block a country" → CloudFront geo restriction or a WAF geo match rule.
Common traps
- "Add the attacker's IP to the ALB's NACL when CloudFront is in front." The NACL sees CloudFront edge IPs, not the client. Use WAF on CloudFront.
- "Remove the IP from the security group to block it." If the SG allows
0.0.0.0/0, everyone is allowed; SGs can't express "everyone but this IP".
Check yourself
Create an AWS WAF web ACL with an IP set rule that blocks the address (and maybe a rate-based rule for the login path), and associate it with the CloudFront distribution. A NACL wouldn't work, because traffic reaches the VPC from CloudFront's IPs.
AWS documentation
Caching strategies
The places to cache along a request on AWS - CloudFront, API Gateway, ElastiCache and DAX - and how TTL, network, computation, cost and latency change as the cache moves closer to the user.
High performance computing (HPC)
The AWS services that help run HPC workloads - data transfer, EC2 instances and cluster placement groups, enhanced networking with ENA and the Elastic Fabric Adapter, high-IOPS storage like FSx for Lustre, and automation with AWS Batch, ParallelCluster and AWS PCS.