Alb
The Alb component lets you create a standalone Application Load Balancer that can be
shared across multiple services.
Create a shared ALB
const vpc = new sst.aws.Vpc("MyVpc");
const alb = new sst.aws.Alb("SharedAlb", { vpc, domain: "app.example.com", listeners: [ { port: 80, protocol: "http" }, { port: 443, protocol: "https" }, ],});Attach services to the ALB
new sst.aws.Service("Api", { cluster, image: "api:latest", loadBalancer: { instance: alb, rules: [ { listen: "443/https", forward: "8080/http", conditions: { path: "/api/*" }, priority: 100 }, ], },});Reference an existing ALB
const alb = sst.aws.Alb.get("SharedAlb", "arn:aws:elasticloadbalancing:...");Constructor
new Alb(name, args, opts?)Parameters
-
namestring -
argsAlbArgs -
opts?ComponentResourceOptions
AlbArgs
domain?
Type string | Object
Set a custom domain for the load balancer.
Automatically manages domains hosted on AWS Route 53, Cloudflare, and Vercel. For other
providers, you’ll need to pass in a cert that validates domain ownership and add the
DNS records.
{ domain: "example.com"}For domains on Cloudflare:
{ domain: { name: "example.com", dns: sst.cloudflare.dns() }}domain.aliases?
Type string[]
Alias domains that should also point to this load balancer.
domain.cert?
Type Input<string>
The ARN of an ACM certificate that proves ownership of the domain. By default, a certificate is created and validated automatically.
domain.dns?
Type false | sst.aws.dns | sst.cloudflare.dns | sst.vercel.dns
Default sst.aws.dns
The DNS provider to use. Defaults to AWS Route 53.
Set to false for manual DNS setup.
domain.name
Type string
The custom domain name.
listeners
Type AlbListenerArgs[]
The listeners for the load balancer. Each entry creates a listener on the specified port and protocol.
{ listeners: [ { port: 80, protocol: "http" }, { port: 443, protocol: "https" } ]}public?
Type Input<boolean>
Default true
Configure if the load balancer should be public (internet-facing) or private (internal).
When set to false, the load balancer endpoint will only be accessible within the VPC.
transform?
Type Object
Transform how this component creates its underlying resources.
transform.listener?
Type ListenerArgs | (args: ListenerArgs, opts: ComponentResourceOptions, name: string) => void
Transform the AWS Load Balancer listener resource.
transform.loadBalancer?
Type LoadBalancerArgs | (args: LoadBalancerArgs, opts: ComponentResourceOptions, name: string) => void
Transform the AWS Load Balancer resource.
transform.securityGroup?
Type SecurityGroupArgs | (args: SecurityGroupArgs, opts: ComponentResourceOptions, name: string) => void
Transform the AWS Security Group resource for the Load Balancer.
vpc
Type Vpc | Input<Object>
The VPC to deploy the ALB in. Can be an SST Vpc component or a custom VPC configuration.
Using an SST Vpc component:
{ vpc: myVpc}Using a custom VPC:
{ vpc: { id: "vpc-0123456789abcdef0", publicSubnets: ["subnet-abc", "subnet-def"], privateSubnets: ["subnet-ghi", "subnet-jkl"] }}vpc.id
Type Input<string>
The VPC ID.
vpc.privateSubnets
Type Input<Input<string>[]>
The private subnet IDs.
vpc.publicSubnets
Type Input<Input<string>[]>
The public subnet IDs.
Properties
arn
Type Output<string>
The ARN of the load balancer.
dnsName
Type Output<string>
The DNS name of the load balancer.
nodes
Type Object
The underlying resources this component creates.
nodes.listeners
Type Record<string, Listener>
The AWS Listener resources, keyed by “PROTOCOLPORT” (e.g. “HTTPS443”).
nodes.loadBalancer
Type LoadBalancer
The AWS Load Balancer resource.
nodes.securityGroup
Type SecurityGroup
The AWS Security Group resource.
securityGroupId
Type Output<string>
The security group ID of the load balancer.
url
Type Output<string>
The URL of the load balancer. If a custom domain is set, this will be the custom
domain URL (eg. https://app.example.com/). Otherwise, it’s the ALB’s DNS name.
zoneId
Type Output<string>
The zone ID of the load balancer.
SDK
Use the SDK in your runtime to interact with your infrastructure.
Links
This is accessible through the Resource object in the SDK.
-
urlstringThe URL of the load balancer. If a custom domain is set, this will be the custom domain URL (eg.
https://app.example.com/). Otherwise, it’s the ALB’s DNS name.
Methods
getListener
getListener(protocol, port)Parameters
-
protocolstring -
portnumber
Returns Listener
Get a specific listener by protocol and port.
const listener = alb.getListener("https", 443);static get
Alb.get(name, loadBalancerArn, opts?)Parameters
The name of the component.namestring
The ARN of the existing ALB.loadBalancerArnInput<string>
Component resource options.opts?ComponentResourceOptions
Returns Alb
Reference an existing ALB by its ARN.
const alb = sst.aws.Alb.get("SharedAlb", "arn:aws:elasticloadbalancing:...");AlbListenerArgs
port
Type number
The port to listen on.
{ port: 443}protocol
Type “https” | “http”
The protocol to listen on. Only http and https are supported (ALB-only).
{ protocol: "https"}