SSL Termination and Sticky Sessions
Offload TLS at the load balancer using ACM certificates, and enable sticky sessions when stateful workloads require client affinity.
SSL Termination and Sticky Sessions is a free AWS Solutions Architect lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
SSL/TLS Termination at the Load Balancer
SSL/TLS termination means the load balancer decrypts incoming HTTPS traffic, inspects the plaintext HTTP request (for routing decisions), and then optionally re-encrypts the request before forwarding to the backend. When termination happens at the ALB, your application servers can receive unencrypted HTTP traffic from the load balancer, simplifying backend configuration.
Termination at the load balancer reduces CPU overhead on application servers (no TLS handshake per connection), enables content-based routing (which requires reading HTTP headers), and centralises certificate management.
AWS Certificate Manager (ACM) Integration
AWS Certificate Manager (ACM) provisions, manages, and renews SSL/TLS certificates at no extra cost. ALB and NLB integrate directly with ACM: you select an ACM certificate in the HTTPS listener configuration and the load balancer presents it to connecting clients.
ACM certificates are automatically renewed before expiry—no manual renewal, no downtime due to expired certificates. For public certificates, ACM validates domain ownership via DNS validation (CNAME record in Route 53) or email validation. For internal use, ACM Private CA can issue private certificates.
# Request a public certificate in ACM
aws acm request-certificate \
--domain-name api.example.com \
--subject-alternative-names '*.example.com' \
--validation-method DNS \
--region us-east-1
# Create an HTTPS listener using the ACM certificate
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:us-east-1:123456789:loadbalancer/app/my-alb/abc \
--protocol HTTPS \
--port 443 \
--ssl-policy ELBSecurityPolicy-TLS13-1-2-2021-06 \
--certificates CertificateArn=arn:aws:acm:us-east-1:123456789:certificate/cert-id \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-tg/xyzServer Name Indication (SNI)
SNI (Server Name Indication) is a TLS extension that allows a single IP address (and therefore a single ALB or NLB listener) to serve multiple TLS certificates for different domain names. The client includes the hostname it is trying to reach in the TLS ClientHello message, and the load balancer selects the appropriate certificate.
ALB supports SNI natively: you can attach multiple ACM certificates to a single HTTPS listener. The ALB automatically selects the right certificate based on the client's SNI hostname. This eliminates the need for a separate listener or load balancer per domain, enabling true virtual hosting with SSL.
# Add a second certificate to an existing HTTPS listener (SNI)
aws elbv2 add-listener-certificates \
--listener-arn arn:aws:elasticloadbalancing:us-east-1:123456789:listener/app/my-alb/abc/lis456 \
--certificates CertificateArn=arn:aws:acm:us-east-1:123456789:certificate/second-cert-idSSL Security Policies
ALB and NLB support configurable SSL security policies that control which TLS protocol versions and cipher suites the load balancer accepts from clients. AWS provides predefined policies (e.g., ELBSecurityPolicy-TLS13-1-2-2021-06) that are updated as new vulnerabilities are discovered.
Compliance requirements may dictate specific TLS versions: PCI-DSS 3.2.1 requires TLS 1.2 minimum; many modern standards recommend disabling TLS 1.0 and 1.1 entirely. Use a policy that excludes deprecated protocols and weak cipher suites. Prefer policies that include TLS 1.3 for forward secrecy and performance.
# List available SSL policies
aws elbv2 describe-ssl-policies \
--query 'SslPolicies[*].{Name:Name,TLSVersions:SslProtocols}' \
--output tableEnd-to-End Encryption vs Termination
Two distinct TLS approaches on ALB:
- SSL termination (most common): ALB decrypts at the load balancer, forwards plain HTTP to targets. Simple, enables routing inspection, reduces server CPU. Backend traffic is unencrypted within the VPC.
- End-to-end TLS: ALB decrypts, then re-encrypts before forwarding to targets (HTTPS between ALB and target). More CPU-intensive, requires certificates on targets, but ensures encryption within VPC for strict compliance scenarios.
For NLB in TLS pass-through mode: NLB does not decrypt at all—it forwards raw TCP to the target which handles TLS. The application server manages its own certificate.
Sticky Sessions: What and Why
Sticky sessions (also called session affinity) ensure that all requests from the same client are consistently routed to the same target within a target group. This is necessary for stateful applications that store session data in-memory on individual servers (rather than in a shared cache like ElastiCache).
Without sticky sessions, a stateless load balancer might send request 1 to server A (which stores the session) and request 2 to server B (which has no session data), causing the user to appear logged out or lose cart contents. Sticky sessions bind a client to a specific target for the duration of the session.
Cookie-Based Stickiness on ALB
ALB supports two types of sticky session cookies:
- Duration-based stickiness (LB-generated cookie): ALB generates a cookie named
AWSALB(for ALB) and sets an expiry duration. The cookie contains an encrypted reference to the target. The client sends this cookie on subsequent requests. - Application-based stickiness: uses an existing cookie set by your application. ALB reads the cookie name you specify, generates an encrypted version in its own cookie, and uses it for sticky routing while preserving the original application cookie.
Configure stickiness per target group, with a duration from 1 second to 7 days.
# Enable duration-based sticky sessions on a target group
aws elbv2 modify-target-group-attributes \
--target-group-arn arn:aws:elasticloadbalancing:us-east-1:123456789:targetgroup/my-tg/xyz \
--attributes \
Key=stickiness.enabled,Value=true \
Key=stickiness.type,Value=lb_cookie \
Key=stickiness.lb_cookie.duration_seconds,Value=86400Drawbacks of Sticky Sessions
While sticky sessions solve the stateful application problem, they introduce trade-offs:
- Uneven load distribution: some targets may receive more traffic if certain clients are unusually active, defeating the purpose of load balancing
- Scaling limitations: if a sticky target becomes unhealthy, sessions are broken—the client must start a new session with a new target, losing any in-memory session data
- Reduced elasticity: sticky sessions make it harder to drain and terminate instances during scale-in events
Best practice: eliminate the need for sticky sessions by externalising session state to ElastiCache or DynamoDB. This makes your application truly stateless and enables full horizontal scaling.
NLB TLS Listener and Pass-Through
NLB supports TLS listeners on port 443 (or any port) for TLS termination, similar to ALB. The NLB decrypts traffic, optionally re-encrypts, and forwards to targets. Alternatively, NLB can pass through encrypted TCP traffic without decrypting if you configure a TCP listener—in this mode, the application server handles TLS end-to-end.
NLB TLS termination with ACM provides the same certificate management benefits as ALB but without HTTP-layer features. Use NLB TLS termination when you need static IPs with TLS termination, or when your backend protocol is non-HTTP (e.g., a custom TCP protocol).
Connection Draining and Sticky Sessions Interaction
When a sticky target is deregistered (e.g., during an Auto Scaling scale-in), connection draining allows in-flight requests to complete. However, new requests from sticky clients that still hold the AWSALB cookie for the draining target are assigned to a new target automatically—the stickiness cookie is invalidated for that client.
This combination of deregistration delay and cookie invalidation ensures graceful transitions: existing long-lived requests finish, while new requests from those clients are smoothly rerouted to healthy targets without appearing as errors to the end user.
Best Practices for SSL and Session Management
Exam-relevant best practices:
- Use ACM certificates for automatic renewal—never manually manage certificates on load balancers
- Use TLS 1.2+ security policies; disable TLS 1.0/1.1 for PCI/HIPAA compliance
- Prefer stateless architectures (session in ElastiCache/DynamoDB) over sticky sessions
- Use SNI on ALB to serve multiple domains from one listener without multiple certificates on separate load balancers
- For strict compliance (data in-VPC must be encrypted): use HTTPS target groups with end-to-end TLS, not just termination at the load balancer
Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: ALB SSL/TLS termination with ACM certificates provides automatic renewal and SNI for multiple domains, SSL security policies control TLS version and cipher suites for compliance, and sticky sessions route users to the same target for stateful apps but are best replaced by externalising session state to ElastiCache. Next up we explore Auto Scaling Groups and launch templates.
Frequently asked questions
Is the “SSL Termination and Sticky Sessions” lesson free?
Yes — the full text of “SSL Termination and Sticky Sessions” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “SSL Termination and Sticky Sessions”?
Offload TLS at the load balancer using ACM certificates, and enable sticky sessions when stateful workloads require client affinity. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “SSL Termination and Sticky Sessions” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- ALB vs NLB vs GLB: When to Use Which
- Target Groups and Health Checks
- Listener Rules and Path-Based Routing
- SSL Termination and Sticky Sessions