Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): configure schema discovery on event bus #32739

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,30 @@
},
"StatementId": "cdk-Statement2"
}
},
"BusSchemaDiscoveryE6A342A5": {
"Type": "AWS::EventSchemas::Discoverer",
"Properties": {
"CrossAccount": true,
"Description": {
"Fn::Join": [
"",
[
"Schema Discoverer for ",
{
"Ref": "BusEA82B648"
},
" Event Bus"
]
]
},
"SourceArn": {
"Fn::GetAtt": [
"BusEA82B648",
"Arn"
]
}
}
}
},
"Parameters": {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ bus.addToResourcePolicy(new iam.PolicyStatement({
resources: [bus.eventBusArn],
}));

bus.schemaDiscovery('SchemaDiscovery');

new IntegTest(app, 'IntegTest-EventBusStack', {
testCases: [stack],
});
16 changes: 16 additions & 0 deletions packages/aws-cdk-lib/aws-events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,22 @@ bus.archive('MyArchive', {
});
```

## Schema Discovery

It is possible to automatically generate schemas in Schema Registry for events sent to an event bus. This is useful for discovering what events are sent to the event bus.

```ts
const bus = new events.EventBus(this, 'bus', {
eventBusName: 'MyCustomEventBus',
description: 'MyCustomEventBus',
});

bus.schemaDiscovery('MySchemaDiscovery', {
crossAccount: true,
description: 'MyCustomerEventBus Schema Discovery',
});
```

## Dead-Letter Queue for EventBus

It is possible to configure a [Dead Letter Queue for an EventBus](https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-rule-event-delivery.html#eb-rule-dlq). This is useful when you want to capture events that could not be delivered to any of the targets.
Expand Down
37 changes: 37 additions & 0 deletions packages/aws-cdk-lib/aws-events/lib/event-bus.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
import { Construct } from 'constructs';
import { Archive, BaseArchiveProps } from './archive';
import { CfnEventBus, CfnEventBusPolicy } from './events.generated';
import * as eventschemas from '../../aws-eventschemas';
import * as iam from '../../aws-iam';
import * as kms from '../../aws-kms';
import * as sqs from '../../aws-sqs';
import { ArnFormat, IResource, Lazy, Names, Resource, Stack, Token } from '../../core';

/**
* Properties to configure schema discovery on an event bus
*/
interface SchemaDiscoveryProps {
/**
* Allows for the discovery of the event schemas that are sent to the event bus from another account
*
* @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eventschemas-discoverer.html#cfn-eventschemas-discoverer-crossaccount
* @default - none
*/
readonly crossAccount: boolean;

/**
* A description for the discoverer
*
* @link https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eventschemas-discoverer.html#cfn-eventschemas-discoverer-description
* @default - none
*/
readonly description: string;
};

/**
* Interface which all EventBus based classes MUST implement
*/
Expand Down Expand Up @@ -50,6 +72,13 @@ export interface IEventBus extends IResource {
*/
archive(id: string, props: BaseArchiveProps): Archive;

/**
* Create an EventBridge schema discoverer to automatically generate schemas based on events on this event bus.
*
* @param props Properties of the schema discoverer
*/
schemaDiscovery(id: string, props?: SchemaDiscoveryProps): eventschemas.CfnDiscoverer;

/**
* Grants an IAM Principal to send custom events to the eventBus
* so that they can be matched to rules.
Expand Down Expand Up @@ -175,6 +204,14 @@ abstract class EventBusBase extends Resource implements IEventBus {
});
}

public schemaDiscovery(id: string, props?: SchemaDiscoveryProps): eventschemas.CfnDiscoverer {
return new eventschemas.CfnDiscoverer(this, id, {
crossAccount: props?.crossAccount ?? true,
description: props?.description || `Schema Discoverer for ${this.eventBusName} Event Bus`,
sourceArn: this.eventBusArn,
});
}

public grantPutEventsTo(grantee: iam.IGrantable): iam.Grant {
return iam.Grant.addToPrincipal({
grantee,
Expand Down
Loading
Loading