@architect/plugin-lambda-invoker

2.0.0 • Public • Published

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

Package Sidebar

Install

npm i @architect/plugin-lambda-invoker

Weekly Downloads

393

Version

2.0.0

License

Apache-2.0

Unpacked Size

13.5 kB

Total Files

4

Last publish

Collaborators

  • brianleroux
  • dam
  • kborchers
  • ryanblock
  • architectci
  • filmaj