Skip to content

Commit fd750a5

Browse files
authored
feat(aws-eventbridge-lambda): Support for custom EventBus (#354)
* enhanced construct to support custom EventBus * fix linting issues * fix PR review comments * refactoring and use IEventBus instead of EventBus * update the props naming convention to align with existing constructs * updated the props documentation * upated exisitingEventBusInterface & eventBusProps description Co-authored-by: santhosh <>
1 parent 876073b commit fd750a5

14 files changed

+1809
-4
lines changed

Diff for: source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,15 @@ _Parameters_
6161
|:-------------|:----------------|-----------------|
6262
|existingLambdaObj?|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Existing instance of Lambda Function object, providing both this and `lambdaFunctionProps` will cause an error.|
6363
|lambdaFunctionProps?|[`lambda.FunctionProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.FunctionProps.html)|User provided props to override the default props for the Lambda function.|
64+
|existingEventBusInterface?|[`events.IEventBus`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.IEventBus.html)| Optional user-provided custom EventBus for construct to use. Providing both this and `eventBusProps` results an error.|
65+
|eventBusProps?|[`events.EventBusProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.EventBusProps.html)|Optional user-provided properties to override the default properties when creating a custom EventBus. Setting this value to `{}` will create a custom EventBus using all default properties. If neither this nor `existingEventBusInterface` is provided the construct will use the `default` EventBus. Providing both this and `existingEventBusInterface` results an error.|
6466
|eventRuleProps|[`events.RuleProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.RuleProps.html)|User provided eventRuleProps to override the defaults|
6567

6668
## Pattern Properties
6769

6870
| **Name** | **Type** | **Description** |
6971
|:-------------|:----------------|-----------------|
72+
|eventBus|[`events.IEventBus`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.IEventBus.html)|Returns the instance of events.IEventBus used by the construct|
7073
|eventsRule|[`events.Rule`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-events.Rule.html)|Returns an instance of events.Rule created by the construct|
7174
|lambdaFunction|[`lambda.Function`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-lambda.Function.html)|Returns an instance of lambda.Function created by the construct|
7275

@@ -82,7 +85,7 @@ Out of the box implementation of the Construct without any override will set the
8285
* Enable reusing connections with Keep-Alive for NodeJs Lambda function
8386
* Enable X-Ray Tracing
8487
* Set Environment Variables
85-
* AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)
88+
* AWS_NODEJS_CONNECTION_REUSE_ENABLED (for Node 10.x and higher functions)
8689

8790
## Architecture
8891
![Architecture Diagram](architecture.png)

Diff for: source/patterns/@aws-solutions-constructs/aws-eventbridge-lambda/lib/index.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ export interface EventbridgeToLambdaProps {
3535
* @default - Default props are used
3636
*/
3737
readonly lambdaFunctionProps?: lambda.FunctionProps,
38+
/**
39+
* Existing instance of a custom EventBus.
40+
*
41+
* @default - None
42+
*/
43+
readonly existingEventBusInterface?: events.IEventBus,
44+
/**
45+
* A new custom EventBus is created with provided props.
46+
*
47+
* @default - None
48+
*/
49+
readonly eventBusProps?: events.EventBusProps,
3850
/**
3951
* User provided eventRuleProps to override the defaults
4052
*
@@ -45,6 +57,7 @@ export interface EventbridgeToLambdaProps {
4557

4658
export class EventbridgeToLambda extends Construct {
4759
public readonly lambdaFunction: lambda.Function;
60+
public readonly eventBus?: events.IEventBus;
4861
public readonly eventsRule: events.Rule;
4962

5063
/**
@@ -70,7 +83,13 @@ export class EventbridgeToLambda extends Construct {
7083
})
7184
};
7285

73-
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([lambdaFunc]);
86+
// build an event bus if existingEventBus is provided or eventBusProps are provided
87+
this.eventBus = defaults.buildEventBus(this, {
88+
existingEventBusInterface: props.existingEventBusInterface,
89+
eventBusProps: props.eventBusProps
90+
});
91+
92+
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([lambdaFunc], this.eventBus);
7493
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);
7594

7695
this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps);

0 commit comments

Comments
 (0)