# API Reference
## Constructs
### TestEventRegistry
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.
Pass it to `TestEvents` via the `registry` property so the test events are
deployed after the registry.
*Example*
```typescript
const registry = new TestEventRegistry(this, 'TestEventRegistry');
new TestEvents(this, 'MyFunctionTestEvents', {
function: myLambda,
registry,
testEvents: [{ name: 'MyEvent', payload: { id: '1' } }],
});
```
#### Initializers
```typescript
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.* |
---
##### `scope`Required
- *Type:* constructs.Construct
---
##### `id`Required
- *Type:* string
---
#### Methods
| **Name** | **Description** |
| --- | --- |
| toString | Returns a string representation of this construct. |
---
##### `toString`
```typescript
public toString(): string
```
Returns a string representation of this construct.
#### Static Functions
| **Name** | **Description** |
| --- | --- |
| isConstruct | Checks if `x` is a construct. |
---
##### ~~`isConstruct`~~
```typescript
import { TestEventRegistry } from 'cdk-lambda-test-events'
TestEventRegistry.isConstruct(x: any)
```
Checks if `x` is a construct.
###### `x`Required
- *Type:* any
Any object.
---
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| node | constructs.Node | The tree node. |
| registryName | string | The name of the registry (always `lambda-testevent-schemas`). |
---
##### `node`Required
```typescript
public readonly node: Node;
```
- *Type:* constructs.Node
The tree node.
---
##### `registryName`Required
```typescript
public readonly registryName: string;
```
- *Type:* string
The name of the registry (always `lambda-testevent-schemas`).
---
### TestEvents
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).
> [TestEventRegistry](TestEventRegistry)
#### Initializers
```typescript
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.* |
---
##### `scope`Required
- *Type:* constructs.Construct
---
##### `id`Required
- *Type:* string
---
##### `props`Required
- *Type:* TestEventsProps
---
#### Methods
| **Name** | **Description** |
| --- | --- |
| toString | Returns a string representation of this construct. |
---
##### `toString`
```typescript
public toString(): string
```
Returns a string representation of this construct.
#### Static Functions
| **Name** | **Description** |
| --- | --- |
| isConstruct | Checks if `x` is a construct. |
| fromFile | Loads a test event from a JSON file. |
---
##### ~~`isConstruct`~~
```typescript
import { TestEvents } from 'cdk-lambda-test-events'
TestEvents.isConstruct(x: any)
```
Checks if `x` is a construct.
###### `x`Required
- *Type:* any
Any object.
---
##### `fromFile`
```typescript
import { TestEvents } from 'cdk-lambda-test-events'
TestEvents.fromFile(filePath: string, name?: string)
```
Loads a test event from a JSON file.
The file must contain a JSON object, which is used as the event payload.
###### `filePath`Required
- *Type:* string
path to the JSON file.
---
###### `name`Optional
- *Type:* string
the display name of the test event;
defaults to the file
name without its extension
---
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| node | constructs.Node | The tree node. |
| schemaName | string | The name of the schema holding the test events. |
---
##### `node`Required
```typescript
public readonly node: Node;
```
- *Type:* constructs.Node
The tree node.
---
##### `schemaName`Required
```typescript
public readonly schemaName: string;
```
- *Type:* string
The name of the schema holding the test events.
---
## Structs
### TestEvent
#### Initializer
```typescript
import { TestEvent } from 'cdk-lambda-test-events'
const testEvent: TestEvent = { ... }
```
#### Properties
| **Name** | **Type** | **Description** |
| --- | --- | --- |
| name | string | The display name for this test event. |
| payload | {[ key: string ]: any} | The event payload as a key-value map. |
---
##### `name`Required
```typescript
public readonly name: string;
```
- *Type:* string
The display name for this test event.
Must be unique within a `TestEvents` construct and consist of at most
25 letters, numbers, dots, hyphens and underscores.
---
##### `payload`Required
```typescript
public readonly payload: {[ key: string ]: any};
```
- *Type:* {[ key: string ]: any}
The event payload as a key-value map.
---
### TestEventsProps
#### Initializer
```typescript
import { TestEventsProps } from 'cdk-lambda-test-events'
const testEventsProps: TestEventsProps = { ... }
```
#### Properties
| **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. |
| registry | TestEventRegistry | The registry to register the test events in. |
| schemaName | string | The name of the schema holding the test events. |
---
##### `function`Required
```typescript
public readonly function: IFunction;
```
- *Type:* aws-cdk-lib.aws_lambda.IFunction
The Lambda function to attach test events to.
---
##### `testEvents`Required
```typescript
public readonly testEvents: TestEvent[];
```
- *Type:* TestEvent[]
List of test events to register.
---
##### `registry`Optional
```typescript
public readonly registry: TestEventRegistry;
```
- *Type:* TestEventRegistry
- *Default:* the `lambda-testevent-schemas` registry is assumed to already exist
The registry to register the test events in.
When provided, the test events are deployed after the registry, which is
required when both live in the same stack (or app).
---
##### `schemaName`Optional
```typescript
public readonly schemaName: string;
```
- *Type:* string
- *Default:* `_${function.functionName}-schema`
The name of the schema holding the test events.
The Lambda Console looks for a schema named `_-schema`.
Only override this when that name cannot be derived from `function`,
e.g. for an imported function whose name is not known.
---