An Application Load Balancer (ALB) serves as a single point of contact for clients and distributes incoming application traffic across multiple targets, such as containers and Lambda functions. It operates at the application layer (layer 7) and is ideal for load balancing HTTP and HTTPS traffic.
ALBs can be integrated with various compute resources, offload SSL/TLS termination, and be configured with custom domain names or fronted by a CDN.
Under the hood, Stacktape uses AWS Application Load Balancer.
When to use them
ALBs are a good fit for most modern cloud applications. They offer high throughput and low latency, making them suitable for demanding workloads.
Advantages
- Predictable pricing: ALBs have a predictable pricing model, which can be more cost-effective than HTTP API Gateways for high-traffic applications.
- Scalability: ALBs can handle millions of requests per second and scale automatically as traffic grows.
- Health checks: When used with container workloads, an ALB periodically checks the health of each container and only routes traffic to healthy ones.
- Content-based routing: ALBs can route requests to different services based on the content of the request, such as the URL path, HTTP header, or query string.
- Security: You can offload SSL/TLS termination to the load balancer, encrypting traffic between the client and the ALB.
Disadvantages
- Fixed cost: ALBs have a fixed monthly cost (around $20/month), even if they are idle. For low-traffic applications, an HTTP API Gateway might be a more cost-effective choice.
Basic usage
ApplicationLoadBalancerAPI referencetypeRequired
Type: string "application-load-balancer"
properties.interfaceDefault: internet
internet (public) or internal (VPC-only). Internal ALBs are not reachable from the internet.
Type: string ENUM
Possible values: internalinternet
properties.customDomains
Custom domains.
Type: Array of string or Array of DomainConfiguration
By default, Stacktape creates DNS records and TLS certificates for each domain.
If you manage DNS yourself, set disableDnsRecordCreation and provide customCertificateArn.
Backward compatible format string[] is still supported.
properties.listeners
Custom listeners (port + protocol). Defaults to HTTPS on 443 + HTTP on 80 (redirecting to HTTPS).
Type: Array of ApplicationLoadBalancerListener
properties.cdn
Put a CDN (CloudFront) in front of this load balancer for caching and lower latency worldwide.
properties.alarms
Alarms for this load balancer (merged with global alarms from the Stacktape Console).
Type: Array of ApplicationLoadBalancerAlarm
properties.disabledGlobalAlarms
Global alarm names to exclude from this load balancer.
Type: Array of string
properties.useFirewall
Name of a web-app-firewall resource to protect this load balancer from common web exploits.
Type: string
overrides
Escape hatch to modify the underlying CloudFormation resources Stacktape creates.
Type: Object
Use dot-notation paths to override specific properties on any child resource.
Find resource logical IDs with stacktape stack-info --detailed.
overrides:
MyDbInstance:
Properties.StorageEncrypted: true
An Application Load Balancer with a Lambda function integration.
Integrating with compute resources
You can forward requests from an ALB to your compute resources by creating an event integration on a multi-container workload, function, or batch job.
Each integration must specify:
loadBalancerName: The name of the ALB that will forward requests.priority: A number that determines the order in which the integration rules are evaluated (from lowest to highest).condition: A set of rules that determine which requests are forwarded to the resource. Conditions can be based on the URL path, query string, headers, and other request properties.
The following example shows two integrations:
- The first integration forwards all requests (
*) to a multi-container workload. - The second integration, which has a lower priority and is evaluated first, forwards any requests with a URL path prefixed with
/lambda-service/to a Lambda function.
An ALB with integrations for both a function and a multi-container workload.
For more information, see the documentation on integrating ALBs with functions, multi-container workloads, and batch jobs.
Custom domain names
You can use a custom domain for your ALB. If you don't have one, you can register one through Stacktape.
If you already have a domain, you can either let Stacktape manage it (if you use AWS Route 53 for DNS) or use a third-party DNS provider.
For more details, see the Domains and Certificates page.
Using Stacktape to manage domains and certs
By default, Stacktape creates DNS records and TLS certificates for each domain.
If you manage DNS yourself, set disableDnsRecordCreation and provide customCertificateArn.
Backward compatible format string[] is still supported.
Using a 3rd-party DNS
To use a domain from a provider like GoDaddy or Cloudflare:
- Create or import a TLS certificate for your domain in the AWS Certificate Manager console and copy its ARN.
- Configure a listener on your load balancer to use the custom certificate.
- After deploying, find the ALB's domain name in the Stacktape Console.
- In your DNS provider's dashboard, create a
CNAMEorALIASrecord pointing to the ALB's domain name.
A custom HTTPS listener with a custom certificate and an automatic redirect from HTTP to HTTPS.
Custom listeners
Listeners check for connection requests from clients, using the protocol and port that you configure. You can define rules for a listener that determine how the load balancer routes requests to its registered targets.
Custom listeners (port + protocol). Defaults to HTTPS on 443 + HTTP on 80 (redirecting to HTTPS).
ApplicationLoadBalancerListenerAPI referenceParent:ApplicationLoadBalancerprotocolRequired
Listener protocol. HTTPS requires a TLS certificate (auto-created with customDomains or via customCertificateArns).
Type: string ENUM
Possible values: HTTPHTTPS
portRequired
Port this listener accepts traffic on (e.g., 443 for HTTPS, 80 for HTTP).
Type: number
customCertificateArns
ARNs of your own ACM certificates. Not needed if using customDomains (Stacktape creates certs automatically).
Type: Array of string
whitelistIps
Restrict access to specific IP addresses/CIDRs. Default: all IPs allowed.
Type: Array of string
defaultAction
Action for requests that don't match any integration. Currently supports redirect only.
Type: LbRedirect
An ALB with a single listener and a function integration.
Default listener action
The default action for a listener determines what to do with a request that doesn't match any of the listener's rules.
Redirect
You can configure a listener to redirect incoming requests to a different URL. For example, you can redirect all HTTP requests on port 80 to an HTTPS listener on port 443.
LbRedirectAPI referenceParent:ApplicationLoadBalancerListenertypeRequired
The type of the default action.
Type: string "redirect"
properties.statusCodeRequired
HTTP_301 (permanent) or HTTP_302 (temporary) redirect.
Type: string ENUM
Possible values: HTTP_301HTTP_302
properties.path
Redirect path (must start with /). Use #{path} to reuse the original path.
Type: string
properties.query
Query string for the redirect (without leading ?). Use #{query} to preserve the original.
Type: string
properties.port
Redirect port (1-65535). Use #{port} to keep the original.
Type: number
properties.host
Redirect hostname. Use #{host} to keep the original.
Type: string
properties.protocol
Redirect protocol. Cannot redirect HTTPS to HTTP.
Type: string ENUM
Possible values: HTTPHTTPS
CDN
You can place an AWS CloudFront CDN in front of your ALB to cache content and reduce latency.
Put a CDN (CloudFront) in front of this load balancer for caching and lower latency worldwide.
For more information, see the CDN documentation.
Using a firewall
You can protect your ALB with a web application firewall (WAF).
Name of a web-app-firewall resource to protect this load balancer from common web exploits.
To learn more, see the Web Application Firewall documentation.
Referenceable parameters
The following parameters can be easily referenced using $ResourceParam directive directive.
To learn more about referencing parameters, refer to referencing parameters.
default domain name of load balancer
- Usage:
$ResourceParam('<<resource-name>>', 'domain')
Comma-separated list of custom domain names assigned to the Load balancer (only available if you use custom domain names)
- Usage:
$ResourceParam('<<resource-name>>', 'customDomains')
Default domain of the CDN distribution (only available if you DO NOT configure custom domain names for the CDN).
- Usage:
$ResourceParam('<<resource-name>>', 'cdnDomain')
Default url of the CDN distribution (only available if you DO NOT configure custom domain names for the CDN).
- Usage:
$ResourceParam('<<resource-name>>', 'cdnUrl')
Comma-separated list of custom domain names assigned to the CDN (only available if you configure custom domain names for the CDN).
- Usage:
$ResourceParam('<<resource-name>>', 'cdnCustomDomains')
Comma-separated list of custom domain name URLs of the CDN (only available if you configure custom domain names for the CDN).
- Usage:
$ResourceParam('<<resource-name>>', 'cdnCustomDomainUrls')