@architect/plugin-lambda-invoker

中文文档
2.0.3发布于 2025/06/26Apache-2.0CommonJS近 30 天下载 3883

Interactively invoke Lambdas in Architect Sandbox with arbitrary events

原始使用文档
文档目录6 节
  1. @architect/plugin-lambda-invoker
  2. Install
  3. Usage
  4. CLI
  5. Programmatic
  6. Invocation mocks

@architect/plugin-lambda-invoker

Interactively invoke Lambdas in Architect Sandbox with arbitrary events

GitHub CI status

Install

Into your existing Architect project:

npm i @architect/plugin-lambda-invoker --save-dev

Add the following to your Architect project manifest (usually app.arc):

@plugins
architect/plugin-lambda-invoker

Usage

CLI

While Sandbox is running, type i in your terminal to bring up the Lambda invocation menu. Then select the Lambda you'd like to invoke.

By default, this plugin will populate your menu with all @events, @queues, @scheduled, and @tables-streams; you can limit this menu (or expand it with additional pragmas) by adding the following setting to a pref[erence]s.arc file:

@sandbox
invoker http scheduled # This would populate @http + @scheduled Lambdas, and ignore all others

Tip: you can navigate the invocation menu by typing numbers (zero-indexed)!

Programmatic

The plugin also passes through the Sandbox invoker for programmatic use (such as in a test environment). This method is only available after Sandbox has finished initializing.

let sandbox = require('@architect/sandbox')
let invokerPlugin = require('@architect/plugin-lambda-invoker')

await sandbox.start()
await invokerPlugin.invoke({
  pragma: 'scheduled',
  name: 'my-scheduled-event',
  payload: { ok: true },
})
await sandbox.end()

Invocation mocks

By default, Lambdas are invoked with an empty payload ({}); if you'd like to invoke your Lambdas with arbitrary payloads, create a file containing invocation mocks.

Invocation mock files live in your root with one of these filenames: sandbox-invoke-mocks.json or sandbox-invoke-mocks.js. These files should be structured like so:

Assuming this project manifest:

@events
background-task

@queues
analytics

@scheduled
backup-database

@tables-streams
tableName

If you wanted to add one or more mocks to each of the three Lambdas above, create the following sandbox-invoke-mocks.js (or equivalent JSON) file with the format of [pragmaName][lambdaName][mockName]:

module.exports = {
  events: {
    'background-task': {
      'my-first-mock': { /* payload */ },
      'another-mock': { /* payload */ },
    }
  },
  queues: {
    analytics: {
      'one-more-mock': { /* payload */ },
      'just-a-mock': { /* payload */ },
    }
  },
  scheduled: {
    'backup-database': {
      'a-mock-for-this': { /* payload */ },
      'the-last-mock': { /* payload */ },
    }
  },
  'tables-streams':{
    tableName:{
      INSERT:{ /* payload */ },
      MODIFY:{ /* payload */ },
      REMOVE:{ /* payload */ },
    }
  }
}

Tip: when using sandbox-invoke-mocks.js, you can dynamically (synchronously) generate mocks on startup

版本与发布记录

@architect/plugin-lambda-invoker 共发布 22 个版本,首次发布于 2022/03/21;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.0.3latest2025/06/261.4 年前
2.0.22025/03/311.6 年前
2.0.12024/07/212 年前
2.0.02024/05/102 年前
1.2.02023/09/013 年前
1.2.0-RC.1RC2023/08/313 年前

关于 @architect/plugin-lambda-invoker 的常见问题

@architect/plugin-lambda-invoker 是什么?

Interactively invoke Lambdas in Architect Sandbox with arbitrary events

如何安装 @architect/plugin-lambda-invoker?

在项目目录运行 npm install @architect/plugin-lambda-invoker,或使用 pnpm add / yarn add / bun add。

@architect/plugin-lambda-invoker 支持 TypeScript 吗?

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

@architect/plugin-lambda-invoker 支持 ESM 还是 CommonJS?

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

@architect/plugin-lambda-invoker 需要什么版本的 Node.js?

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

@architect/plugin-lambda-invoker 可以商用吗?

@architect/plugin-lambda-invoker 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@architect/plugin-lambda-invoker 的下载量有多少?

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

@architect/plugin-lambda-invoker 还在维护吗?

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