{"record":{"id":"d6897d96ad4c1f49","repo":"anomalyco/sst","slug":"failed-to-publish-event-to-bus","errorCode":null,"errorMessage":"Failed to publish event to bus","messagePattern":"Failed to publish event to bus","errorType":"error_code","errorClass":"PublishError","httpStatus":null,"severity":"error","filePath":"sdk/js/src/aws/bus.ts","lineNumber":80,"sourceCode":"            {\n              Source: [Resource.App.name, Resource.App.stage].join(\".\"),\n              DetailType: evt.type,\n              Detail: JSON.stringify({\n                metadata: evt.metadata,\n                properties: evt.properties,\n              }),\n              EventBusName: typeof name === \"string\" ? name : name.name,\n            },\n          ],\n        }),\n      },\n      options,\n    )\n      .catch((e) => {\n        if (e instanceof Error) console.log(\"cause\", e.cause);\n        throw e;\n      });\n    if (!res.ok) throw new PublishError(res);\n    return res.json();\n  }\n\n  export class PublishError extends Error {\n    constructor(public readonly response: Response) {\n      super(\"Failed to publish event to bus\");\n    }\n  }\n}\n","sourceCodeStart":62,"sourceCodeEnd":90,"githubUrl":"https://github.com/anomalyco/sst/blob/a0bd20f762883e72a35caccb4896c42ce5b3f707/sdk/js/src/aws/bus.ts#L62-L90","documentation":"`bus.publish` sends an event to Amazon EventBridge via the PutEvents API using awsFetch. If the HTTP response is not OK (e.g. 4xx/5xx from EventBridge or a signing/network failure at the fetch level surfaced by awsFetch), a `PublishError` is thrown with the message \"Failed to publish event to bus\"; the original `Response` is attached to the error as `error.response` for inspecting the AWS error body.","triggerScenarios":"Any `bus.publish(...)` call where the EventBridge PutEvents request returns a non-OK HTTP status: invalid event bus name, missing IAM `events:PutEvents` permission for the function's role, event detail exceeding size limits, or AWS throttling/errors.","commonSituations":"Function's IAM role lacks PutEvents on the bus; publishing to a bus that was renamed or removed across stages; `Resource` app name/stage mismatch causing wrong bus ARN; oversized event payloads (EventBridge 256KB limit); local dev without AWS credentials (see client error).","solutions":["Inspect `error.response` and read the response body for the exact AWS error code (AccessDeniedException, ResourceNotFoundException, etc.).","Grant the publishing function's IAM role `events:PutEvents` on the target event bus, and link the bus resource to the function.","Verify the bus name/resource passed to publish exists in the current stage.","Reduce event size below 256KB if the payload is large, then retry with backoff for throttling errors."],"exampleFix":"try {\n  await bus.publish(Resource.MyBus, event);\n} catch (e) {\n  if (e instanceof bus.PublishError) {\n    const detail = await e.response.text();\n    console.error(\"PutEvents failed:\", e.response.status, detail);\n  }\n}","handlingStrategy":"retry","validationCode":"import { Resource } from \"sst\";\nif (!Resource[busName]) throw new Error(`Bus ${busName} is not linked to this function`);","typeGuard":"function isPublishError(e: unknown): e is bus.PublishError {\n  return e instanceof bus.PublishError && typeof e.response === \"object\";\n}","tryCatchPattern":"for (let attempt = 0; attempt < 3; attempt++) {\n  try {\n    return await bus.publish(Resource.MyBus, event);\n  } catch (e) {\n    if (e instanceof bus.PublishError && e.response.status < 500) throw e;\n    await new Promise(r => setTimeout(r, 2 ** attempt * 100));\n  }\n}\nthrow new Error(\"Publish failed after retries\");","preventionTips":["Link the bus resource to publishing functions so IAM permissions are generated automatically.","Keep event payloads under the 256KB EventBridge limit.","Check `e.response.status` to distinguish retryable (5xx/throttling) from permanent (4xx) errors."],"tags":["aws","eventbridge","network","iam"],"backgroundTag":"aws-api-request-failed","analyzedSha":"a0bd20f762883e72a35caccb4896c42ce5b3f707","analyzedAt":"2026-08-30T11:26:00.383Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}