{"record":{"id":"32cb77c8625939a6","repo":"anomalyco/sst","slug":"container-cn-in-loadbalancer-rules-does-not","errorCode":null,"errorMessage":"Container \"${cn}\" in \"loadBalancer.rules\" does not match any container in Service \"${name}\". Available: ${[...containerNames].join(\", \")}.","messagePattern":"Container \"(.+?)\" in \"loadBalancer\\.rules\" does not match any container in Service \"(.+?)\"\\. Available: (.+?)\\.","errorType":"validation","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/service.ts","lineNumber":2637,"sourceCode":"        );\n      }\n\n      // Validate container names (no resources created here)\n      containers.apply((ctrs) => {\n        const containerNames = new Set(ctrs.map((c) => c.name));\n        if (ctrs.length > 1) {\n          for (const rule of rules) {\n            if (!rule.container) {\n              throw new VisibleError(\n                `You must provide a \"container\" name in each rule when there is more than one container in Service \"${name}\".`,\n              );\n            }\n          }\n        }\n        for (const rule of rules) {\n          const cn = rule.container ?? ctrs[0].name;\n          if (!containerNames.has(cn)) {\n            throw new VisibleError(\n              `Container \"${cn}\" in \"loadBalancer.rules\" does not match any container in Service \"${name}\". Available: ${[...containerNames].join(\", \")}.`,\n            );\n          }\n        }\n      });\n\n      // Create target groups in a plain loop (no apply)\n      const targets: Record<string, lb.TargetGroup> = {};\n      const rawEntries: {\n        targetGroup: lb.TargetGroup;\n        explicitContainer: string | undefined;\n        containerPort: number;\n      }[] = [];\n\n      for (const rule of rules) {\n        const parts = rule.forward.split(\"/\");\n        const forwardPort = parseInt(parts[0]);\n        const forwardProtocol = parts[1].toUpperCase();","sourceCodeStart":2619,"sourceCodeEnd":2655,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/service.ts#L2619-L2655","documentation":"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.","triggerScenarios":"Setting container: \"web\" when containers are named \"app\"/\"api\"; renaming a container without updating ALB rules; a typo like capitalization differences.","commonSituations":"Refactors that rename containers; copying rules between services with different container names; plural/singular mistakes (\"worker\" vs \"workers\").","solutions":["Set container to one of the names listed in the error's Available list","If the intended container is missing, define it in the Service's containers","Fix the typo/case to match the container definition"],"exampleFix":"// before\nrules: [{ listen: \"443/https\", container: \"web\", ... }]\n// after (containers: [{ name: \"app\", ... }])\nrules: [{ listen: \"443/https\", container: \"app\", ... }]","handlingStrategy":"validation","validationCode":"const names = new Set(config.containers.map(c => c.name));\nfor (const r of attachment.rules)\n  if (r.container && !names.has(r.container))\n    throw new Error(`container \"${r.container}\" not defined; available: ${[...names].join(\", \")}`);","typeGuard":"const isValidContainer = (name: string, containers: { name: string }[]) =>\n  containers.some(c => c.name === name);","tryCatchPattern":"null","preventionTips":["Reference container names via exported constants instead of string literals","Update ALB rules in the same PR that renames containers","Echo the container list in config validation errors"],"tags":["load-balancer","containers","validation"],"backgroundTag":"invalid-reference","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}