Verify that the ALB forwards requests to instances
The EC2 instance user-data produced this test output, demonstrating the ALB successfully forwards requests to the application servers:Application Load Balancer (ALB)
- The ALB is the public entry point for the application. In this lab it is internet-facing and listens on HTTP (port 80).
- When a client sends an HTTP request, the ALB accepts the request and forwards it to one of the EC2 instances registered in its target group.
- The ALB can also be attached to an AWS WAF web ACL for application-layer inspection (described below).
Load balancer security group
- The ALB has a security group that controls which inbound traffic the load balancer will accept.
- In this setup the ALB security group allows inbound HTTP (TCP 80) from the public internet (
0.0.0.0/0), enabling the ALB to receive requests from any client.

EC2 instances security group
- The application EC2 instances use a separate security group (EC2-SG).
- EC2-SG allows HTTP (port 80) only from the ALB security group (LB-SG) instead of from the Internet. This forces all HTTP traffic to flow through the ALB and prevents direct internet access to the instances.

Security groups are stateful: when the ALB establishes a connection to an EC2 instance, the instance can send return traffic without requiring an explicit outbound rule for the response. NACLs are stateless and require explicit inbound and outbound rules for both directions.
Network ACLs (NACLs) and subnet-level controls
- ALBs are typically deployed across multiple Availability Zones; each AZ provides a subnet for the ALB, so the ALB will have one or more subnets mapped across AZs for fault tolerance.

- NACLs are attached to subnets. To determine which NACL protects the ALB subnets, open the VPC console and check the Network ACLs associated with those subnets.
- NACLs contain an ordered set of rules (evaluated by rule number) that explicitly allow or deny traffic. Because they are stateless, you must allow both inbound and outbound traffic explicitly for a communication flow to succeed.

Security groups vs NACLs — quick comparison
AWS WAF (Web Application Firewall)
- AWS WAF inspects HTTP/HTTPS requests and can allow, block, or count them based on rules you define—examples include IP allow/deny lists, rate-based throttling, and pattern matching for known attack signatures.
- Attach a WAF web ACL to the ALB to add application-layer protection on top of the existing network controls (NACLs and security groups). WAF operates at Layer 7 and is ideal for mitigating OWASP-style web threats.

This demo does not include an active WAF configuration. If you deploy WAF rules in production, test them carefully (use
COUNT actions first) to avoid unintentionally blocking legitimate traffic.Summary and best practices
- Use an internet-facing ALB as the single public ingress point and limit direct instance exposure.
- Attach a security group to the ALB that permits client traffic (e.g., HTTP/80 or HTTPS/443).
- Configure instance security groups to accept traffic only from the ALB security group to prevent direct access to EC2 instances.
- Apply NACLs at the subnet level for additional coarse-grained controls, remembering they are stateless.
- Use AWS WAF on the ALB for application-layer protections such as IP blocklists, rate limiting, and pattern-based filtering.
Links and references
- AWS Application Load Balancer Documentation
- Security Groups for Your VPC
- Network ACLs
- AWS WAF Developer Guide