{"record":{"id":"5e95ea543e3dfc62","repo":"anomalyco/sst","slug":"cannot-access-nodes-loadbalancer-when-no-public","errorCode":null,"errorMessage":"Cannot access `nodes.loadBalancer` when no public ports are exposed.","messagePattern":"Cannot access `nodes\\.loadBalancer` when no public ports are exposed\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/service-v1.ts","lineNumber":838,"sourceCode":"       * The Amazon ECS Task Definition.\n       */\n      get taskDefinition() {\n        if ($dev)\n          throw new VisibleError(\n            \"Cannot access `nodes.taskDefinition` in dev mode.\",\n          );\n        return self.taskDefinition!;\n      },\n      /**\n       * The Amazon Elastic Load Balancer.\n       */\n      get loadBalancer() {\n        if ($dev)\n          throw new VisibleError(\n            \"Cannot access `nodes.loadBalancer` in dev mode.\",\n          );\n        if (!self.loadBalancer)\n          throw new VisibleError(\n            \"Cannot access `nodes.loadBalancer` when no public ports are exposed.\",\n          );\n        return self.loadBalancer;\n      },\n    };\n  }\n\n  /** @internal */\n  public getSSTLink() {\n    return {\n      properties: { url: $dev ? this.devUrl : this._url },\n    };\n  }\n}\n\nconst __pulumiType = \"sst:aws:Service\";\n// @ts-expect-error\nService.__pulumiType = __pulumiType;","sourceCodeStart":820,"sourceCodeEnd":856,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/service-v1.ts#L820-L856","documentation":"This is the deploy-time counterpart to the dev-mode guard: `nodes.loadBalancer` is only valid when the Service was created with public ports exposed. If no load balancer exists (`self.loadBalancer` is undefined), SST throws this `VisibleError` to explain that the property is unavailable rather than returning undefined.","triggerScenarios":"On `sst deploy`, reading `nodes.loadBalancer` from a Service that has no `public` ports in its container/port config, or that uses an external ALB attachment without a managed LB.","commonSituations":"Teams switching a service from public to internal ports (or removing the `public` config) and forgetting downstream code still reads `nodes.loadBalancer`; internal-only services where no ALB is created.","solutions":["Expose at least one public port via the `public` ports config so a load balancer is created.","Guard the access: check `if (!$dev)` and only read `nodes.loadBalancer` for services with public ports.","If the service must be internal, reference your own separately-created `sst.aws.LoadBalancer` component instead."],"exampleFix":"// before\nconst lb = svc.nodes.loadBalancer;\n\n// after\nconst svc = new sst.aws.Service(\"Api\", {\n  containers: [{ name: \"app\", image: \"...\", public: { ports: [{ http: 80 }] } }]\n});\nconst lb = svc.nodes.loadBalancer; // now valid","handlingStrategy":"validation","validationCode":"// ensure the Service config exposes public ports before reading nodes.loadBalancer\nconst hasPublicPorts = (args: sst.aws.ServiceArgs) =>\n  args.containers?.some((c) => c.public?.ports && c.public.ports.length > 0) ?? false;\nif (!hasPublicPorts(serviceArgs)) throw new Error(\"Add public ports to use nodes.loadBalancer\");","typeGuard":"function exposesPublicPorts(args: sst.aws.ServiceArgs): boolean {\n  return Array.isArray(args.containers) &&\n    args.containers.some((c) => (c.public?.ports?.length ?? 0) > 0);\n}","tryCatchPattern":"try {\n  return svc.nodes.loadBalancer;\n} catch (e) {\n  if (e instanceof VisibleError && e.message.includes(\"no public ports\")) return null;\n  throw e;\n}","preventionTips":["Only access `nodes.loadBalancer` for services configured with `public` ports.","For internal services, create and reference an explicit `sst.aws.LoadBalancer` component.","Re-check `nodes` usage after switching services between public and internal."],"tags":["aws","ecs","alb","configuration","sst"],"backgroundTag":"resource-not-configured","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}