anomalyco/sst · error · VisibleError

Container "${cn}" in "loadBalancer.rules" does not match any

Error message

Container "${cn}" in "loadBalancer.rules" does not match any container in Service "${name}". Available: ${[...containerNames].join(", ")}.

What it means

Each rule's container name (or the inferred first container) must exist in the Service's container list. SST validates this to avoid creating target groups pointing at non-existent containers and lists the valid names in the message.

Source

Thrown at platform/src/components/aws/service.ts:2637

        );
      }

      // Validate container names (no resources created here)
      containers.apply((ctrs) => {
        const containerNames = new Set(ctrs.map((c) => c.name));
        if (ctrs.length > 1) {
          for (const rule of rules) {
            if (!rule.container) {
              throw new VisibleError(
                `You must provide a "container" name in each rule when there is more than one container in Service "${name}".`,
              );
            }
          }
        }
        for (const rule of rules) {
          const cn = rule.container ?? ctrs[0].name;
          if (!containerNames.has(cn)) {
            throw new VisibleError(
              `Container "${cn}" in "loadBalancer.rules" does not match any container in Service "${name}". Available: ${[...containerNames].join(", ")}.`,
            );
          }
        }
      });

      // Create target groups in a plain loop (no apply)
      const targets: Record<string, lb.TargetGroup> = {};
      const rawEntries: {
        targetGroup: lb.TargetGroup;
        explicitContainer: string | undefined;
        containerPort: number;
      }[] = [];

      for (const rule of rules) {
        const parts = rule.forward.split("/");
        const forwardPort = parseInt(parts[0]);
        const forwardProtocol = parts[1].toUpperCase();

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Set container to one of the names listed in the error's Available list
  2. If the intended container is missing, define it in the Service's containers
  3. Fix the typo/case to match the container definition

Example fix

// before
rules: [{ listen: "443/https", container: "web", ... }]
// after (containers: [{ name: "app", ... }])
rules: [{ listen: "443/https", container: "app", ... }]
Defensive patterns

Strategy: validation

Validate before calling

const names = new Set(config.containers.map(c => c.name));
for (const r of attachment.rules)
  if (r.container && !names.has(r.container))
    throw new Error(`container "${r.container}" not defined; available: ${[...names].join(", ")}`);

Type guard

const isValidContainer = (name: string, containers: { name: string }[]) =>
  containers.some(c => c.name === name);

Try / catch

null

Prevention

When it happens

Trigger: Setting container: "web" when containers are named "app"/"api"; renaming a container without updating ALB rules; a typo like capitalization differences.

Common situations: Refactors that rename containers; copying rules between services with different container names; plural/singular mistakes ("worker" vs "workers").

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/32cb77c8625939a6. Report an issue: GitHub.