Skip to content

feat: add standalone Alb component for shared load balancers#6395

Open
ekaya97 wants to merge 1 commit intoanomalyco:devfrom
ekaya97:feat/standalone-alb-component
Open

feat: add standalone Alb component for shared load balancers#6395
ekaya97 wants to merge 1 commit intoanomalyco:devfrom
ekaya97:feat/standalone-alb-component

Conversation

@ekaya97
Copy link
Contributor

@ekaya97 ekaya97 commented Feb 6, 2026

Summary

Add a standalone Alb component that can be shared across multiple Service instances. This allows multiple ECS services to share a single Application Load Balancer with path-based routing.

Fixes #6017 #5510

New API

// Create a shared ALB
const alb = new sst.aws.Alb("SharedAlb", {
  vpc,
  listeners: [{ port: 80, protocol: "http" }],
});

// Attach services with routing rules
new sst.aws.Service("Api", {
  cluster,
  loadBalancer: {
    instance: alb,
    rules: [
      {
        listener: "80/http",
        forward: "3000/http",
        conditions: { path: "/api/*" },
        priority: 100,
      },
    ],
  },
});

Features

  • Alb component — standalone ALB with HTTP/HTTPS listeners, SSL/TLS, and DNS integration
  • Service integrationloadBalancer.instance option for attaching to external ALBs
  • Routing rules — path, header, and query string condition-based routing with explicit priorities
  • Reference patternAlb.get(name, arn) with lazy listener discovery for cross-stack references
  • Linkable — implements Link.Linkable, exposes url for SST linking

Files Changed

File Changes
platform/src/components/aws/alb.ts New 705-line ALB component
platform/src/components/aws/service.ts Union-typed loadBalancer prop, ALB attachment logic
platform/src/components/aws/index.ts Export Alb
platform/package.json Added @types/node devDependency
platform/vitest.config.ts Vitest config (fixes @types/node resolution)
platform/test/components/alb.test.ts 10 unit tests
platform/test/components/service-alb.test.ts 9 integration tests
examples/aws-shared-alb/ HTTP example
examples/aws-shared-alb-domain/ HTTPS with custom domain example

Test plan

  • Unit tests pass (35 tests total)
  • Deployed aws-shared-alb example to AWS — 7/7 tests pass
  • Deployed aws-shared-alb-domain example to AWS — 9/9 tests pass (SSL, HTTP→HTTPS redirect)

HTTP Example Test Results

Screenshot 2026-02-06 at 16 24 38

HTTPS Example Test Results

Screenshot 2026-02-06 at 16 23 17

🤖 Generated with Claude Code

Add a standalone `Alb` component that can be shared across multiple `Service` instances.
Services can attach to a shared ALB using path-based routing rules with explicit priorities.

- Add `Alb` component with HTTP/HTTPS listeners, SSL/TLS support, and DNS integration
- Add `loadBalancer.instance` option to Service for attaching to external ALBs
- Add `loadBalancer.rules` for path/header/query condition-based routing
- Add `Alb.get()` reference pattern with lazy listener discovery
- Add unit tests for Alb (10 tests) and Service+ALB integration (9 tests)
- Add examples: aws-shared-alb (HTTP) and aws-shared-alb-domain (HTTPS with custom domain)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@nicholasgubbins
Copy link
Contributor

nicholasgubbins commented Feb 9, 2026

this is super nice @ekaya97

excited to be able to do router.route(${subdomain}.{domain}, sharedAlb.url)

@ekaya97
Copy link
Contributor Author

ekaya97 commented Feb 9, 2026

@nicholasgubbins

Thanks!

Check out my other PR #6379 - similar kind of extension concerning WAF in Router.

@vimtor vimtor self-assigned this Feb 10, 2026
@teodorrd27
Copy link

This is so valuable I've monkey patched my existing sst deployment to deploy in production. It'll be great to see this merged. Thanks for your effort. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flexible load balancer for Service

4 participants