@coorpacademy/serverless-offline-eventbridge

中文文档
1.0.1发布于 2026/07/07MITCommonJS近 30 天下载 2680

Emulate AWS λ and EventBridge locally when developing your Serverless project

原始使用文档
文档目录9 节
  1. Serverless Framework v4
  2. Installation
  3. How it works?
  4. Configure
  5. Functions
  6. CloudFormation AWS::Events::Rule resources
  7. EventBridge plugin options
  8. Supported EventPattern content filters
  9. Attribution

@coorpacademy/serverless-offline-eventbridge

This Serverless-offline plugin emulates AWS λ and EventBridge on your local machine. It exposes a local PutEvents endpoint, routes every published event through a real EventBridge EventPattern matcher, and invokes the matching handlers through serverless-offline's own Lambda runner.

Features:

  • In-process PutEvents endpoint + in-memory event bus — no extra container required.
  • Real EventBridge EventPattern matching (source, detail-type, nested detail, resources, $or, and the content filters prefix, suffix, anything-but, exists, equals-ignore-case, numeric, wildcard, cidr).
  • Honors both function-level eventBridge: events and raw CloudFormation AWS::Events::Rule resources.
  • Retry with backoff, and optional destinations.onFailure (DLQ) simulation against a local SQS endpoint.

Serverless Framework v4

This plugin supports both Serverless Framework v3 and v4. It takes the logger from the plugin constructor's 3rd argument ({log}) and falls back to console when it is absent, so no configuration change is required when upgrading.

Installation

First, add @coorpacademy/serverless-offline-eventbridge to your project:

npm install @coorpacademy/serverless-offline-eventbridge

Then inside your project's serverless.yml file, add the following entry to the plugins section before serverless-offline:

plugins:
  - '@coorpacademy/serverless-offline-eventbridge'
  - serverless-offline

How it works?

By default the plugin starts a tiny in-process HTTP server (Node core http, no extra dependency) that accepts AWS PutEvents requests (X-Amz-Target: AWSEvents.PutEvents, Content-Type: application/x-amz-json-1.1). Each published entry is turned into the canonical EventBridge event envelope, matched against every subscriber's EventPattern, and the matching Lambda handlers are invoked through serverless-offline. A target failure never fails the PutEvents response (mirroring AWS), but is retried and, once retries are exhausted, optionally routed to the function's destinations.onFailure.

Point your AWS SDK EventBridge client at http://<host>:<port> (default http://127.0.0.1:4010) to publish events locally.

Configure

Functions

Function-level eventBridge events follow the serverless documentation.

functions:
  myHandler:
    handler: handler.compute
    events:
      - eventBridge:
          eventBus: default
          pattern:
            source:
              - my.app
            detail-type:
              - OrderPlaced
            detail:
              status:
                - CONFIRMED

CloudFormation AWS::Events::Rule resources

Rules declared directly in resources are also honored: the plugin scans for AWS::Events::Rule resources whose Targets[].Arn is {Fn::GetAtt: [<FunctionLogicalId>, Arn]}, maps the target back to its function, and registers the rule's EventPattern.

resources:
  Resources:
    OrderPlacedRule:
      Type: AWS::Events::Rule
      Properties:
        EventBusName: default
        EventPattern:
          source:
            - my.app
          detail-type:
            - OrderPlaced
        Targets:
          - Id: myHandler
            Arn:
              Fn::GetAtt:
                - MyHandlerLambdaFunction
                - Arn

EventBridge plugin options

Configure the plugin via a custom: serverless-offline-eventbridge object in your serverless.yml:

custom:
  serverless-offline-eventbridge:
    host: 127.0.0.1            # bind host for the PutEvents endpoint
    port: 4010                 # PutEvents endpoint port
    accountId: '000000000000'  # event `account` + event-bus ARN
    maximumRetryAttempts: 10   # dispatch retry budget
    retryDelayMs: 500          # delay between retries
    debug: false               # verbose logging of options + subscriptions
    mockServer: true           # run the in-process PutEvents endpoint
    simulateDestinations: true # route exhausted async failures to destinations.onFailure
    endpoint: http://localhost:9324  # AWS endpoint for the onFailure SQS / opt-in subscribe clients
    subscribe: false           # opt-in: poll a real `events` bus at `endpoint`
    pollInterval: 1000         # LocalStack opt-in poll cadence (ms)
OptionDefaultPurpose
host127.0.0.1bind host for the PutEvents endpoint
port4010PutEvents endpoint port
regionfrom provider.regionevent region field + ARN build
accountId000000000000event account + event-bus ARN
maximumRetryAttempts10dispatch retry budget
retryDelayMs500delay between retries
debugfalseverbose logging
endpointundefinedAWS endpoint for the onFailure SQS / opt-in subscribe clients
subscribefalseopt-in: poll a real events bus at endpoint
mockServertruerun the in-process PutEvents endpoint
simulateDestinationstrueroute exhausted async failures to destinations.onFailure
pollInterval1000LocalStack opt-in poll cadence (ms)

Supported EventPattern content filters

prefix (including {prefix: {equals-ignore-case}}), suffix, anything-but, exists, equals-ignore-case, numeric (multi-clause, e.g. ['>', 0, '<=', 100]), wildcard (* glob), and cidr. An unknown filter key is treated as a non-match (it never throws).

Attribution

The EventPattern matching algorithm is adapted in spirit from rubenkaiser/serverless-offline-aws-eventbridge (MIT), rewritten as pure lodash/fp helpers. See NOTICE.

版本与发布记录

@coorpacademy/serverless-offline-eventbridge 共发布 2 个版本,首次发布于 2026/07/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
1.0.1latest2026/07/074 个月前
1.0.02026/07/074 个月前

关于 @coorpacademy/serverless-offline-eventbridge 的常见问题

@coorpacademy/serverless-offline-eventbridge 是什么?

Emulate AWS λ and EventBridge locally when developing your Serverless project

如何安装 @coorpacademy/serverless-offline-eventbridge?

在项目目录运行 npm install @coorpacademy/serverless-offline-eventbridge,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:serverless-offline(>=11)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@coorpacademy/serverless-offline-eventbridge 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/coorpacademy__serverless-offline-eventbridge 是否存在。

@coorpacademy/serverless-offline-eventbridge 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@coorpacademy/serverless-offline-eventbridge 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@coorpacademy/serverless-offline-eventbridge 可以商用吗?

@coorpacademy/serverless-offline-eventbridge 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@coorpacademy/serverless-offline-eventbridge 的下载量有多少?

根据 npm 官方下载统计,@coorpacademy/serverless-offline-eventbridge 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,680 次,日均约 89 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@coorpacademy/serverless-offline-eventbridge 还在维护吗?

最新版本 1.0.1 发布于 2026/07/07(4 个月前);至今共发布 2 个版本,其中过去 12 个月发布了 2 个;首次发布于 2026/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。