{"record":{"id":"b8e5ba6928c2f0b4","repo":"anomalyco/sst","slug":"you-must-provide-a-container-name-in-loadbalancer","errorCode":null,"errorMessage":"You must provide a container name in \"loadBalancer.rules\" when there is more than one container.","messagePattern":"You must provide a container name in \"loadBalancer\\.rules\" when there is more than one container\\.","errorType":"validation","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/service.ts","lineNumber":1962,"sourceCode":"      const inlineLoadBalancer = output(loadBalancer).apply(\n        (lb) => lb as Exclude<typeof lb, { instance: Alb }>,\n      );\n\n      // normalize rules\n      const rules = all([inlineLoadBalancer, containers]).apply(\n        ([lb, containers]) => {\n          // validate rules\n          const lbRules = lb.rules ?? lb.ports;\n          if (!lbRules || lbRules.length === 0)\n            throw new VisibleError(\n              `You must provide the ports to expose via \"loadBalancer.rules\".`,\n            );\n\n          // validate container defined when multiple containers exists\n          if (containers.length > 1) {\n            lbRules.forEach((v) => {\n              if (!v.container)\n                throw new VisibleError(\n                  `You must provide a container name in \"loadBalancer.rules\" when there is more than one container.`,\n                );\n            });\n          }\n\n          // parse protocols and ports\n          const rules = lbRules.map((v) => {\n            const listenParts = v.listen.split(\"/\");\n            const listenPort = parseInt(listenParts[0]);\n            const listenProtocol = listenParts[1];\n            const listenConditions =\n              v.conditions || v.path\n                ? {\n                    path: v.conditions?.path ?? v.path,\n                    query: v.conditions?.query,\n                    header: v.conditions?.header,\n                  }\n                : undefined;","sourceCodeStart":1944,"sourceCodeEnd":1980,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/service.ts#L1944-L1980","documentation":"When a Service runs more than one container, each load balancer rule must name which container it routes to. `normalizeLoadBalancer` validates every rule and throws this `VisibleError` if a rule lacks a `container` field in a multi-container service.","triggerScenarios":"Defining two or more `containers` and a `loadBalancer.rules`/`ports` entry without `container: \"<name>\"`, on `sst deploy`.","commonSituations":"Adding a second (sidecar) container to an existing service whose rules were written when only one container existed; copying single-container examples into multi-container services.","solutions":["Add `container: \"api\"` (the container's `name`) to each rule in `loadBalancer.rules`.","Ensure the referenced container name matches one of the `containers[].name` values exactly.","If rules target the same container, still specify it explicitly since SST cannot infer it with multiple containers."],"exampleFix":"// before\nloadBalancer: { rules: [{ listen: \"443/https\", forward: \"80/http\" }] }\n\n// after\nloadBalancer: { rules: [{ container: \"api\", listen: \"443/https\", forward: \"80/http\" }] }","handlingStrategy":"validation","validationCode":"const containerNames = new Set(args.containers.map((c) => c.name));\nif (args.containers.length > 1) {\n  for (const r of args.loadBalancer.rules) {\n    if (!r.container || !containerNames.has(r.container)) {\n      throw new Error(`Rule must reference a defined container, got: ${r.container}`);\n    }\n  }\n}","typeGuard":"function ruleHasContainer(r: { container?: string }, containers: { name: string }[]): r is { container: string } {\n  return typeof r.container === \"string\" && containers.some((c) => c.name === r.container);\n}","tryCatchPattern":"try {\n  const svc = new sst.aws.Service(\"Api\", args);\n} catch (e) {\n  if (e instanceof VisibleError && e.message.includes(\"container name\")) {\n    args.loadBalancer.rules.forEach((r) => (r.container ??= args.containers[0].name));\n  } else throw e;\n}","preventionTips":["Always set `container` in LB rules, even for single-container services.","Keep rule `container` values in sync with `containers[].name`.","Re-audit LB rules whenever adding or removing containers."],"tags":["aws","ecs","alb","configuration","sst"],"backgroundTag":"missing-required-config","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}