Skip to content

Latest commit

 

History

History
392 lines (244 loc) · 12.5 KB

File metadata and controls

392 lines (244 loc) · 12.5 KB

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.

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' } }],
});

Initializers

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.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

Methods

Name Description
toString Returns a string representation of this construct.
with Applies one or more mixins to this construct.

toString
public toString(): string

Returns a string representation of this construct.

with
public with(mixins: ...IMixin[]): IConstruct

Applies 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.

mixinsRequired
  • Type: ...constructs.IMixin[]

The mixins to apply.


Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
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.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


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

Initializers

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.

scopeRequired
  • Type: constructs.Construct

idRequired
  • Type: string

propsRequired

Methods

Name Description
toString Returns a string representation of this construct.
with Applies one or more mixins to this construct.

toString
public toString(): string

Returns a string representation of this construct.

with
public with(mixins: ...IMixin[]): IConstruct

Applies 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.

mixinsRequired
  • Type: ...constructs.IMixin[]

The mixins to apply.


Static Functions

Name Description
isConstruct Checks if x is a construct.

isConstruct
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.

xRequired
  • Type: any

Any object.


Properties

Name Type Description
node constructs.Node The tree node.

nodeRequired
public readonly node: Node;
  • Type: constructs.Node

The tree node.


Structs

TestEvent

Initializer

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.

nameRequired
public readonly name: string;
  • Type: string

The display name for this test event.


payloadRequired
public readonly payload: {[ key: string ]: any};
  • Type: {[ key: string ]: any}

The event payload as a key-value map.


TestEventsProps

Initializer

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.

functionRequired
public readonly function: IFunction;
  • Type: aws-cdk-lib.aws_lambda.IFunction

The Lambda function to attach test events to.


testEventsRequired
public readonly testEvents: TestEvent[];

List of test events to register.