Skip to main content

cdk-lambda-test-events

npm version constructs.dev

A CDK construct that registers Lambda test events in the AWS Console, making them available to every developer on your team without manual setup.

Test events are stored in the EventBridge Schema Registry under lambda-testevent-schemas — exactly where the Lambda Console looks for them.

Installation

npm install cdk-lambda-test-events

Requires aws-cdk-lib >= 2.166.0 and constructs >= 10.0.5 as peer dependencies.

Prerequisites

The Lambda Console looks for test events in an EventBridge Schema Registry named lambda-testevent-schemas. AWS creates this registry automatically the first time any developer saves a test event via the Console, but the registry must exist before deploying this construct.

In a fresh account or region that has never had a Console-created test event, create it once using TestEventRegistry:

import { TestEventRegistry } from 'cdk-lambda-test-events';

// shared-stack.ts — deploy once per account/region
const registry = new TestEventRegistry(this, 'TestEventRegistry');

Pass the registry to TestEvents via the registry property. This makes sure the test events are deployed after the registry, both within a single stack and across stacks (it adds a stack dependency):

new TestEvents(this, 'MyFunctionTestEvents', {
  function: myLambdaFunction,
  registry,
  testEvents: [{ name: 'HelloWorldEvent', payload: { message: 'Hello, World!' } }],
});

Note: deploy TestEventRegistry in one stack only. Multiple stacks in the same account/region competing for the same physical registry name will cause a CloudFormation conflict.

If the Console has already created the registry (or you prefer the CLI), you can skip TestEventRegistry entirely:

aws schemas create-registry --registry-name lambda-testevent-schemas

Usage

import { TestEvents } from 'cdk-lambda-test-events';

new TestEvents(this, 'MyFunctionTestEvents', {
  function: myLambdaFunction,
  testEvents: [
    {
      name: 'HelloWorldEvent',
      payload: {
        message: 'Hello, World!',
        value: 42,
      },
    },
    {
      name: 'ErrorEvent',
      payload: {
        message: 'Something went wrong',
        httpStatusCode: 500,
      },
    },
  ],
});

After deploying, the events appear in the Lambda Console under Test → Test events for every developer with access to that account.

Loading events from JSON files

Keep larger payloads in separate JSON files and load them with TestEvents.fromFile. The event name defaults to the file name without its extension:

new TestEvents(this, 'MyFunctionTestEvents', {
  function: myLambdaFunction,
  testEvents: [
    TestEvents.fromFile('events/HelloWorldEvent.json'),
    TestEvents.fromFile('events/error.json', 'ErrorEvent'),
  ],
});

The file must contain a JSON object.

Event names

The Lambda Console only accepts test event names of at most 25 letters, numbers, dots (.), hyphens (-) and underscores (_). Names must be unique within a TestEvents construct. Invalid or duplicate names, as well as an empty testEvents list, cause an error at synth time.

Schema name

The Lambda Console looks up test events for a function in a schema named _<function name>-schema, which TestEvents derives from function. Use schemaName to override it, e.g. when the function name cannot be resolved from the IFunction you have:

new TestEvents(this, 'ImportedFunctionTestEvents', {
  function: importedFunction,
  schemaName: '_my-imported-function-schema',
  testEvents: [{ name: 'MyEvent', payload: { id: '1' } }],
});

Generated schema

Besides the examples, TestEvents generates an OpenAPI schema describing the payloads:

  • A property is required only if it is present in every test event.
  • A property that is null in some events is marked nullable.
  • A property with different types across events is described with oneOf.

API

TestEventRegistry

Creates the lambda-testevent-schemas EventBridge Schema Registry. Deploy once per account/region before using TestEvents. Has no configuration properties.

Attribute Type Description
registryName string The name of the registry

TestEvents

Property Type Description
function IFunction The Lambda function to attach test events to
testEvents TestEvent[] List of test events to register (at least one)
registry? TestEventRegistry Registry to deploy after. Default: the registry is assumed to exist
schemaName? string Schema name override. Default: _<function name>-schema
Attribute Type Description
schemaName string The name of the schema holding the test events
Static method Returns Description
fromFile(filePath, name?) TestEvent Loads a test event from a JSON file. name defaults to the file name without extension

TestEvent

Property Type Description
name string Display name shown in the Lambda Console (max 25 letters, numbers, ., -, _; unique)
payload { [key: string]: any } The event payload

LAMBDA_TEST_EVENT_REGISTRY

Exported string constant ("lambda-testevent-schemas") — the registry name used by the Lambda Console.

Contributing

This project is managed with projen. Do not edit generated files (like package.json or tsconfig.json) by hand. Edit .projenrc.ts instead and run:

npx projen

To run tests:

npx projen test

License

Apache-2.0

Metadata

Release files for cdk-lambda-test-events 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cdk-lambda-test-events 0.1.0
File Size Uploaded Provenance Actions
cdk_lambda_test_events-0.1.0.tar.gz 45.5 kB With provenance Details for cdk_lambda_test_events-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cdk-lambda-test-events 0.1.0
File Interpreter ABI Platform Actions
cdk_lambda_test_events-0.1.0-py3-none-any.whl Python 3 none any Details for cdk_lambda_test_events-0.1.0-py3-none-any.whl

Total release size: 89.6 kB

Release files / cdk_lambda_test_events-0.1.0.tar.gz

Download URL cdk_lambda_test_events-0.1.0.tar.gz
Size 45.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0b2f4e5d2b5d4d0ae95183c441ac5bf1043e847c6b0663e897697a6fa92962ec
BLAKE2b-256 checksum
How to use checksums
cd80900771ec1f5bf7e1e2340d7efb138d1cbb8215384fecab3627cb4f327d5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.15.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / cdk_lambda_test_events-0.1.0-py3-none-any.whl

Download URL cdk_lambda_test_events-0.1.0-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
233a23079ef5f5a433904202db38de841b69a4b1563cb28156cabd2379382dd8
BLAKE2b-256 checksum
How to use checksums
62121550775a49304511edd70386cde3c682e3086764951c86858ed36d187bb3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.15.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for cdk-lambda-test-events 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cdk_lambda_test_events-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page