runfabric

Handler Scenarios

Use this guide when you need more than a single default handler. Aligned with upstream HANDLER_SCENARIOS. In this repo the Node runtime adapter is provided by @runfabric/sdk; use createHandler from @runfabric/sdk or its adapters subpath.

Quick navigation

Scenario 1: Single Handler

service: hello-api
provider:
  name: aws-lambda
  runtime: nodejs
functions:
  - name: api
    entry: src/index.ts
    triggers:
      - type: http
        method: GET
        path: /hello
import type { UniversalHandler } from "@runfabric/sdk";

export const handler: UniversalHandler = async (req) => ({
  status: 200,
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ method: req.method, path: req.path }),
});

Scenario 2: Multiple Named Handlers

service: multi-api
provider:
  name: aws-lambda
  runtime: nodejs

functions:
  - name: api
    entry: src/index.ts
    triggers:
      - type: http
        method: GET
        path: /health
  - name: public-api
    entry: src/public.ts
    triggers:
      - type: http
        method: GET
        path: /public
  - name: admin-api
    entry: src/admin.ts
    triggers:
      - type: http
        method: POST
        path: /admin

Deploy one function quickly:

runfabric deploy --function public-api -c runfabric.yml

Scenario 3: Existing Framework Apps

Use createHandler from @runfabric/sdk:

import type { UniversalHandler } from "@runfabric/sdk";
import { createHandler } from "@runfabric/sdk";

export const handler: UniversalHandler = createHandler(appOrFastifyOrNestApp);

Framework wiring checklist:

Scenario 4: Queue + Storage

service: worker-app
provider:
  name: aws-lambda
  runtime: nodejs
functions:
  - name: worker
    entry: src/worker.ts
    triggers:
      - type: queue
        queue: arn:aws:sqs:us-east-1:123456789012:jobs
      - type: storage
        bucket: uploads
        events:
          - s3:ObjectCreated:*