Creates the lambda-testevent-schemas EventBridge Schema Registry that the Lambda Console uses to find test events.
This registry is a prerequisite for TestEvents to work. AWS creates
it automatically the first time you save a test event through the Console,
but in accounts or regions where that has never happened you must create it
yourself — this construct does exactly that.
Deploy it once per account/region, typically in a shared or foundation stack. Adding it to multiple stacks in the same account/region will cause a CloudFormation conflict because they would compete over the same physical resource name.
Example
// shared-stack.ts
new TestEventRegistry(this, 'TestEventRegistry');
// any other stack in the same account/region
new TestEvents(this, 'MyFunctionTestEvents', {
function: myLambda,
testEvents: [{ name: 'MyEvent', payload: { id: '1' } }],
});import { TestEventRegistry } from 'cdk-lambda-test-events'
new TestEventRegistry(scope: Construct, id: string)| Name | Type | Description |
|---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
- Type: constructs.Construct
- Type: string
| Name | Description |
|---|---|
toString |
Returns a string representation of this construct. |
with |
Applies one or more mixins to this construct. |
public toString(): stringReturns a string representation of this construct.
public with(mixins: ...IMixin[]): IConstructApplies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the
start of the call, so constructs added by a mixin will not be visited.
Use multiple with() calls if subsequent mixins should apply to added
constructs.
- Type: ...constructs.IMixin[]
The mixins to apply.
| Name | Description |
|---|---|
isConstruct |
Checks if x is a construct. |
import { TestEventRegistry } from 'cdk-lambda-test-events'
TestEventRegistry.isConstruct(x: any)Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
- Type: any
Any object.
| Name | Type | Description |
|---|---|---|
node |
constructs.Node |
The tree node. |
public readonly node: Node;- Type: constructs.Node
The tree node.
A CDK construct that registers Lambda test events in the EventBridge Schema Registry, making them available in the AWS Console's Lambda test event UI.
Prerequisite: the lambda-testevent-schemas registry must exist in the
account and region before you deploy this construct. Use {@link TestEventRegistry}
to create it, or rely on the AWS Console having created it previously (it is
automatically created the first time a test event is saved via the Console).
import { TestEvents } from 'cdk-lambda-test-events'
new TestEvents(scope: Construct, id: string, props: TestEventsProps)| Name | Type | Description |
|---|---|---|
scope |
constructs.Construct |
No description. |
id |
string |
No description. |
props |
TestEventsProps |
No description. |
- Type: constructs.Construct
- Type: string
- Type: TestEventsProps
| Name | Description |
|---|---|
toString |
Returns a string representation of this construct. |
with |
Applies one or more mixins to this construct. |
public toString(): stringReturns a string representation of this construct.
public with(mixins: ...IMixin[]): IConstructApplies one or more mixins to this construct.
Mixins are applied in order. The list of constructs is captured at the
start of the call, so constructs added by a mixin will not be visited.
Use multiple with() calls if subsequent mixins should apply to added
constructs.
- Type: ...constructs.IMixin[]
The mixins to apply.
| Name | Description |
|---|---|
isConstruct |
Checks if x is a construct. |
import { TestEvents } from 'cdk-lambda-test-events'
TestEvents.isConstruct(x: any)Checks if x is a construct.
Use this method instead of instanceof to properly detect Construct
instances, even when the construct library is symlinked.
Explanation: in JavaScript, multiple copies of the constructs library on
disk are seen as independent, completely different libraries. As a
consequence, the class Construct in each copy of the constructs library
is seen as a different class, and an instance of one class will not test as
instanceof the other class. npm install will not create installations
like this, but users may manually symlink construct libraries together or
use a monorepo tool: in those cases, multiple copies of the constructs
library can be accidentally installed, and instanceof will behave
unpredictably. It is safest to avoid using instanceof, and using
this type-testing method instead.
- Type: any
Any object.
| Name | Type | Description |
|---|---|---|
node |
constructs.Node |
The tree node. |
public readonly node: Node;- Type: constructs.Node
The tree node.
import { TestEvent } from 'cdk-lambda-test-events'
const testEvent: TestEvent = { ... }| Name | Type | Description |
|---|---|---|
name |
string |
The display name for this test event. |
payload |
{[ key: string ]: any} |
The event payload as a key-value map. |
public readonly name: string;- Type: string
The display name for this test event.
public readonly payload: {[ key: string ]: any};- Type: {[ key: string ]: any}
The event payload as a key-value map.
import { TestEventsProps } from 'cdk-lambda-test-events'
const testEventsProps: TestEventsProps = { ... }| Name | Type | Description |
|---|---|---|
function |
aws-cdk-lib.aws_lambda.IFunction |
The Lambda function to attach test events to. |
testEvents |
TestEvent[] |
List of test events to register. |
public readonly function: IFunction;- Type: aws-cdk-lib.aws_lambda.IFunction
The Lambda function to attach test events to.
public readonly testEvents: TestEvent[];- Type: TestEvent[]
List of test events to register.