Skip to main content
This walkthrough explains how layered AWS controls—an internet-facing Application Load Balancer (ALB), security groups, network ACLs (NACLs), and AWS WAF—work together to protect an application running on EC2 instances. You will see how traffic flows from a public client to your application and which controls apply at each stage.

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.
A screenshot of the AWS EC2 Security Groups console on the Inbound rules tab for a security group, showing one inbound rule. The rule permits HTTP (TCP) on port 80 from 0.0.0.0/0.

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.
Screenshot of the AWS EC2 "Security Groups" console showing a list of three security groups (EC2-SG, LB-SG, default) with their security group IDs and VPC links. The top bar shows actions like "Export" and "Create security group."
This yields a controlled path: client -> ALB (public SG) -> EC2 (EC2-SG that only trusts LB-SG)
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.
A screenshot of the AWS EC2 console showing the "Load balancers" page for a load balancer named "LoadBalancer1," listing availability zones and subnet IDs. The top bar includes account/region info and a "Create load balancer" button.
  • 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.
A screenshot of the AWS VPC "Network ACLs" console showing one network ACL (acl-0b69917eeb84b15b2) marked as default. A pop-up lists three associated subnet IDs and the VPC ID.

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.
A screenshot of the AWS WAF (web application firewall) console page showing the large "AWS WAF" heading and description. A right-side panel prompts "Get started with AWS WAF" with a prominent "Create protection pack (web ACL)" button.
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.

Watch Video