{"record":{"id":"be55fcbfad4acd0b","repo":"anomalyco/sst","slug":"cannot-subscribe-to-the-this-constructorname-be55fc","errorCode":null,"errorMessage":"Cannot subscribe to the \"${this.constructorName}\" queue multiple times. An SQS Queue can only have one subscriber.","messagePattern":"Cannot subscribe to the \"(.+?)\" queue multiple times\\. An SQS Queue can only have one subscriber\\.","errorType":"exception","errorClass":"VisibleError","httpStatus":null,"severity":"error","filePath":"platform/src/components/aws/queue.ts","lineNumber":515,"sourceCode":"   * queue.subscribe({\n   *   handler: \"src/subscriber.handler\",\n   *   timeout: \"60 seconds\"\n   * });\n   * ```\n   *\n   * Or pass in the ARN of an existing Lambda function.\n   *\n   * ```js title=\"sst.config.ts\"\n   * queue.subscribe(\"arn:aws:lambda:us-east-1:123456789012:function:my-function\");\n   * ```\n   */\n  public subscribe(\n    subscriber: Input<string | FunctionArgs | FunctionArn>,\n    args?: QueueSubscriberArgs,\n    opts?: ComponentResourceOptions,\n  ) {\n    if (this.isSubscribed)\n      throw new VisibleError(\n        `Cannot subscribe to the \"${this.constructorName}\" queue multiple times. An SQS Queue can only have one subscriber.`,\n      );\n    this.isSubscribed = true;\n\n    return Queue._subscribeFunction(\n      this.constructorName,\n      this.arn,\n      subscriber,\n      args,\n      { ...opts, provider: this.constructorOpts.provider },\n    );\n  }\n\n  /**\n   * Subscribe to an SQS Queue that was not created in your app.\n   *\n   * @param queueArn The ARN of the SQS Queue to subscribe to.\n   * @param subscriber The function that'll be notified.","sourceCodeStart":497,"sourceCodeEnd":533,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/platform/src/components/aws/queue.ts#L497-L533","documentation":"SQS allows only one event source mapping per queue, so a Queue component permits a single subscribe() call. A second call while this.isSubscribed is true throws this VisibleError.","triggerScenarios":"Calling queue.subscribe() twice on the same Queue component instance, e.g. wiring two consumers to one queue.","commonSituations":"Refactoring where a queue is shared by multiple handlers; forgetting SST's one-subscriber constraint versus SNS/EventBridge fan-out.","solutions":["Remove the duplicate subscribe() call","Use SNS, EventBridge, or a fan-out pattern if multiple consumers are needed","Subscribe once with a single handler that dispatches internally"],"exampleFix":"// before\nqueue.subscribe(\"src/consumerA.handler\");\nqueue.subscribe(\"src/consumerB.handler\");\n// after\nqueue.subscribe(\"src/consumer.handler\"); // single handler routes work internally\n// or: fan out via SNS/EventBus to multiple subscribers","handlingStrategy":"validation","validationCode":"if (queue.__isSubscribed) throw new Error(\"Queue already has a subscriber\");\n// track subscriptions in your own app-level map before calling subscribe","typeGuard":"const subscribed = new Set<string>();\nfunction canSubscribe(queueName: string): boolean {\n  return !subscribed.has(queueName);\n}","tryCatchPattern":"try {\n  queue.subscribe(handler);\n} catch (e) {\n  if (String(e).includes(\"only have one subscriber\")) console.error(\"Use SNS/EventBridge fan-out for multiple consumers\");\n  throw e;\n}","preventionTips":["Call subscribe() exactly once per Queue","Use SNS or EventBridge when multiple consumers are needed","Search codebase for queue name usages before adding a second subscriber"],"tags":["sqs","queue","subscribe","configuration"],"backgroundTag":"duplicate-subscription","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}