Skip to content

Commit 60dd243

Browse files
authored
feat(aws-eventbridge-sqs, aws-events-rule-sqs, aws-eventbridge-stepfunctions, aws-events-rule-step-function): custom EventBus support (#363)
* enhanced construct to support custom EventBus * fix linting issues * fix PR review comments * refactoring and use IEventBus instead of EventBus * enchanced aws-eventbridge-sqs construct to support custom eventbus * enhanced aws-eventbridge-stepfunctions construct to support custom eventbus * update the props naming convention to align with existing constructs * updated the props documentation * upated exisitingEventBusInterface & eventBusProps description * upated naming convention as per other aws-evenbridge-* standards * enhance aws-eventbridge-stepfunctions to support custom eventbus * enhance aws-events-rule-step-function construct to support custom eventbus * enhance aws-events-rule-sqs to support custom eventbus * refactor * fix viperlight issue * refactoring to keep it consistent with other constructs * update documentation * fix merge issues * remove duplicate props Co-authored-by: santhosh <>
1 parent 47221d9 commit 60dd243

37 files changed

+8556
-72
lines changed

Diff for: .viperlightignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ source/patterns/@aws-solutions-constructs/aws-lambda-step-function/test/lambda-s
3030
source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/test/lambda-stepfunctions.test.ts:130
3131
source/patterns/@aws-solutions-constructs/aws-events-rule-sns/test/events-rule-sns-topic.test.ts:255
3232
source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/test/eventbridge-sns-topic.test.ts:255
33-
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:131
34-
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:131
33+
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:143
34+
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:143
3535
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:105
3636
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:105
3737
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md:39

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ _Parameters_
6969

7070
| **Name** | **Type** | **Description** |
7171
|:-------------|:----------------|-----------------|
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|
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|
7373
|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|
7474
|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|
7575

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _Parameters_
8080

8181
| **Name** | **Type** | **Description** |
8282
|:-------------|:----------------|-----------------|
83-
|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|
83+
|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|
8484
|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|
8585
|snsTopic|[`sns.Topic`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sns.Topic.html)|Returns an instance of sns.Topic created by the construct|
8686
|encryptionKey?|[`kms.Key`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kms.Key.html)|Returns an instance of kms Key used for the SNS Topic.|

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

+3
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ _Parameters_
6767

6868
| **Name** | **Type** | **Description** |
6969
|:-------------|:----------------|-----------------|
70+
|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.|
71+
|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.|
7072
|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. |
7173
|existingQueueObj?|[`sqs.Queue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.Queue.html)|An optional, existing SQS queue to be used instead of the default queue. Providing both this and `queueProps` will cause an error.|
7274
|queueProps?|[`sqs.QueueProps`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.QueueProps.html)|User provided props to override the default props for the SQS Queue. |
@@ -82,6 +84,7 @@ _Parameters_
8284

8385
| **Name** | **Type** | **Description** |
8486
|:-------------|:----------------|-----------------|
87+
|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|
8588
|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|
8689
|sqsQueue|[`sqs.Queue`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-sqs.Queue.html)|Returns an instance of sqs.Queue created by the construct|
8790
|encryptionKey?|[`kms.Key`](https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-kms.Key.html)|Returns an instance of kms Key used for the SQS queue.|

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

+30-11
Original file line numberDiff line numberDiff line change
@@ -24,72 +24,85 @@ import { overrideProps } from '@aws-solutions-constructs/core';
2424
* @summary The properties for the EventbridgeToSqs Construct
2525
*/
2626
export interface EventbridgeToSqsProps {
27+
/**
28+
* Existing instance of a custom EventBus.
29+
*
30+
* @default - None
31+
*/
32+
readonly existingEventBusInterface?: events.IEventBus;
33+
/**
34+
* A new custom EventBus is created with provided props.
35+
*
36+
* @default - None
37+
*/
38+
readonly eventBusProps?: events.EventBusProps;
2739
/**
2840
* User provided eventRuleProps to override the defaults
2941
*
3042
* @default - None
3143
*/
32-
readonly eventRuleProps: events.RuleProps
44+
readonly eventRuleProps: events.RuleProps;
3345
/**
3446
* Existing instance of SQS queue object, providing both this and queueProps will cause an error.
3547
*
3648
* @default - None
3749
*/
38-
readonly existingQueueObj?: sqs.Queue,
50+
readonly existingQueueObj?: sqs.Queue;
3951
/**
4052
* User provided props to override the default props for the SQS queue.
4153
*
4254
* @default - Default props are used
4355
*/
44-
readonly queueProps?: sqs.QueueProps,
56+
readonly queueProps?: sqs.QueueProps;
4557
/**
4658
* Whether to grant additional permissions to the Lambda function enabling it to purge the SQS queue.
4759
*
4860
* @default - "false", disabled by default.
4961
*/
50-
readonly enableQueuePurging?: boolean,
62+
readonly enableQueuePurging?: boolean;
5163
/**
5264
* Optional user provided properties for the dead letter queue
5365
*
5466
* @default - Default props are used
5567
*/
56-
readonly deadLetterQueueProps?: sqs.QueueProps,
68+
readonly deadLetterQueueProps?: sqs.QueueProps;
5769
/**
5870
* Whether to deploy a secondary queue to be used as a dead letter queue.
5971
*
6072
* @default - true.
6173
*/
62-
readonly deployDeadLetterQueue?: boolean,
74+
readonly deployDeadLetterQueue?: boolean;
6375
/**
6476
* The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue.
6577
*
6678
* @default - required field if deployDeadLetterQueue=true.
6779
*/
68-
readonly maxReceiveCount?: number,
80+
readonly maxReceiveCount?: number;
6981
/**
7082
* Use a KMS Key, either managed by this CDK app, or imported. If importing an encryption key, it must be specified in
7183
* the encryptionKey property for this construct.
7284
*
7385
* @default - true (encryption enabled, managed by this CDK app).
7486
*/
75-
readonly enableEncryptionWithCustomerManagedKey?: boolean
87+
readonly enableEncryptionWithCustomerManagedKey?: boolean;
7688
/**
7789
* An optional, imported encryption key to encrypt the SQS queue, and SNS Topic.
7890
*
7991
* @default - not specified.
8092
*/
81-
readonly encryptionKey?: kms.Key
93+
readonly encryptionKey?: kms.Key;
8294
/**
8395
* Optional user-provided props to override the default props for the encryption key.
8496
*
8597
* @default - Default props are used.
8698
*/
87-
readonly encryptionKeyProps?: kms.KeyProps
99+
readonly encryptionKeyProps?: kms.KeyProps;
88100
}
89101

90102
export class EventbridgeToSqs extends Construct {
91103
public readonly sqsQueue: sqs.Queue;
92104
public readonly deadLetterQueue?: sqs.DeadLetterQueue;
105+
public readonly eventBus?: events.IEventBus;
93106
public readonly eventsRule: events.Rule;
94107
public readonly encryptionKey?: kms.IKey;
95108

@@ -136,7 +149,13 @@ export class EventbridgeToSqs extends Construct {
136149
})
137150
};
138151

139-
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([sqsEventTarget]);
152+
// build an event bus if existingEventBus is provided or eventBusProps are provided
153+
this.eventBus = defaults.buildEventBus(this, {
154+
existingEventBusInterface: props.existingEventBusInterface,
155+
eventBusProps: props.eventBusProps
156+
});
157+
158+
const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([sqsEventTarget], this.eventBus);
140159
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);
141160

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

0 commit comments

Comments
 (0)