Sub topic 8
Terminating TLS with ACM certificates
This chapter assumes you can create an Application Load Balancer with a listener and target group, as covered earlier. You should also know basic DNS and HTTP. The goal is to serve HTTPS from the load balancer while your instances keep serving plain HTTP.
What TLS termination means
TLS termination means the load balancer holds the certificate and private key. It decrypts client traffic and forwards a request to the targets. Your instances no longer spend CPU on handshakes, and you manage certificates in one place.
AWS Certificate Manager (ACM) issues and stores public certificates. ACM renews them automatically when DNS validation is in place. A certificate attached to a load balancer listener never exposes its private key to you.
Request a certificate
Request the certificate in the same Region as the load balancer. ACM certificates are Regional, so a certificate in us-east-1 cannot be used by a load balancer in eu-west-1.
aws acm request-certificate \
--domain-name www.example.com \
--validation-method DNSThe command returns a certificate ARN. Describe the certificate to find the DNS validation record:
aws acm describe-certificate \
--certificate-arn "$CERT_ARN" \
--query "Certificate.DomainValidationOptions[0].ResourceRecord"Create the returned CNAME record in your DNS zone. Once ACM sees it, the status changes from PENDING_VALIDATION to ISSUED. Keep the record in place, because ACM uses it again for renewals.
Add an HTTPS listener
Create a listener on port 443 that references the certificate and a TLS security policy:
aws elbv2 create-listener \
--load-balancer-arn "$ALB_ARN" \
--protocol HTTPS \
--port 443 \
--certificates CertificateArn="$CERT_ARN" \
--ssl-policy ELBSecurityPolicy-TLS13-1-2-2021-06 \
--default-actions Type=forward,TargetGroupArn="$TG_ARN"The security policy sets the allowed TLS versions and cipher suites. Pick a current policy unless old clients force you to allow older protocols.
Redirect HTTP to HTTPS
Change the port 80 listener so it redirects instead of forwarding:
aws elbv2 modify-listener \
--listener-arn "$HTTP_LISTENER_ARN" \
--default-actions 'Type=redirect,RedirectConfig={Protocol=HTTPS,Port=443,StatusCode=HTTP_301}'Common errors
- Certificate not listed: the certificate is in a different Region, or its status is not
ISSUED. - Stuck in
PENDING_VALIDATION: the CNAME record is missing, has a typo, or was added to the wrong DNS zone. - Browser name mismatch: the domain you visit is not covered by the certificate. Request a wildcard such as
*.example.comor add the name as a subject alternative name. - Connection timeout on 443: the load balancer's security group does not allow inbound TCP 443.
Exercise
You requested an ACM certificate in us-east-1, but your ALB is in eu-west-1 and the certificate does not appear when you create the HTTPS listener. What is the cause and the fix?
Show answer
ACM certificates are Regional, so the load balancer can only use certificates from its own Region. Request (and validate) a new certificate for the same domain in eu-west-1, then reference its ARN in the listener.
Exercise
Why should you leave the DNS validation CNAME record in place after the certificate is issued?
Show answer
ACM uses the same record to revalidate the domain when it renews the certificate automatically. If you remove it, renewal can fail and the certificate can expire.