Skip to content

Commit

Permalink
feat(aws-eventbridge-sqs, aws-events-rule-sqs, aws-eventbridge-stepfu…
Browse files Browse the repository at this point in the history
…nctions, 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 <>
  • Loading branch information
surukonda authored Sep 3, 2021
1 parent 47221d9 commit 60dd243
Show file tree
Hide file tree
Showing 37 changed files with 8,556 additions and 72 deletions.
4 changes: 2 additions & 2 deletions .viperlightignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ source/patterns/@aws-solutions-constructs/aws-lambda-step-function/test/lambda-s
source/patterns/@aws-solutions-constructs/aws-lambda-stepfunctions/test/lambda-stepfunctions.test.ts:130
source/patterns/@aws-solutions-constructs/aws-events-rule-sns/test/events-rule-sns-topic.test.ts:255
source/patterns/@aws-solutions-constructs/aws-eventbridge-sns/test/eventbridge-sns-topic.test.ts:255
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:131
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:131
source/patterns/@aws-solutions-constructs/aws-events-rule-sqs/test/events-rule-sqs-queue.test.ts:143
source/patterns/@aws-solutions-constructs/aws-eventbridge-sqs/test/eventbridge-sqs-queue.test.ts:143
source/patterns/@aws-solutions-constructs/aws-dynamodb-stream-lambda/test/dynamodb-stream-lambda.test.ts:105
source/patterns/@aws-solutions-constructs/aws-dynamodbstreams-lambda/test/dynamodbstreams-lambda.test.ts:105
source/patterns/@aws-solutions-constructs/aws-apigateway-iot/README.md:39
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ _Parameters_

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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|
|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|
|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|
|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|

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ _Parameters_

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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|
|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|
|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|
|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|
|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.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ _Parameters_

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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.|
|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.|
|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. |
|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.|
|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. |
Expand All @@ -82,6 +84,7 @@ _Parameters_

| **Name** | **Type** | **Description** |
|:-------------|:----------------|-----------------|
|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|
|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|
|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|
|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.|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,72 +24,85 @@ import { overrideProps } from '@aws-solutions-constructs/core';
* @summary The properties for the EventbridgeToSqs Construct
*/
export interface EventbridgeToSqsProps {
/**
* Existing instance of a custom EventBus.
*
* @default - None
*/
readonly existingEventBusInterface?: events.IEventBus;
/**
* A new custom EventBus is created with provided props.
*
* @default - None
*/
readonly eventBusProps?: events.EventBusProps;
/**
* User provided eventRuleProps to override the defaults
*
* @default - None
*/
readonly eventRuleProps: events.RuleProps
readonly eventRuleProps: events.RuleProps;
/**
* Existing instance of SQS queue object, providing both this and queueProps will cause an error.
*
* @default - None
*/
readonly existingQueueObj?: sqs.Queue,
readonly existingQueueObj?: sqs.Queue;
/**
* User provided props to override the default props for the SQS queue.
*
* @default - Default props are used
*/
readonly queueProps?: sqs.QueueProps,
readonly queueProps?: sqs.QueueProps;
/**
* Whether to grant additional permissions to the Lambda function enabling it to purge the SQS queue.
*
* @default - "false", disabled by default.
*/
readonly enableQueuePurging?: boolean,
readonly enableQueuePurging?: boolean;
/**
* Optional user provided properties for the dead letter queue
*
* @default - Default props are used
*/
readonly deadLetterQueueProps?: sqs.QueueProps,
readonly deadLetterQueueProps?: sqs.QueueProps;
/**
* Whether to deploy a secondary queue to be used as a dead letter queue.
*
* @default - true.
*/
readonly deployDeadLetterQueue?: boolean,
readonly deployDeadLetterQueue?: boolean;
/**
* The number of times a message can be unsuccessfully dequeued before being moved to the dead-letter queue.
*
* @default - required field if deployDeadLetterQueue=true.
*/
readonly maxReceiveCount?: number,
readonly maxReceiveCount?: number;
/**
* Use a KMS Key, either managed by this CDK app, or imported. If importing an encryption key, it must be specified in
* the encryptionKey property for this construct.
*
* @default - true (encryption enabled, managed by this CDK app).
*/
readonly enableEncryptionWithCustomerManagedKey?: boolean
readonly enableEncryptionWithCustomerManagedKey?: boolean;
/**
* An optional, imported encryption key to encrypt the SQS queue, and SNS Topic.
*
* @default - not specified.
*/
readonly encryptionKey?: kms.Key
readonly encryptionKey?: kms.Key;
/**
* Optional user-provided props to override the default props for the encryption key.
*
* @default - Default props are used.
*/
readonly encryptionKeyProps?: kms.KeyProps
readonly encryptionKeyProps?: kms.KeyProps;
}

export class EventbridgeToSqs extends Construct {
public readonly sqsQueue: sqs.Queue;
public readonly deadLetterQueue?: sqs.DeadLetterQueue;
public readonly eventBus?: events.IEventBus;
public readonly eventsRule: events.Rule;
public readonly encryptionKey?: kms.IKey;

Expand Down Expand Up @@ -136,7 +149,13 @@ export class EventbridgeToSqs extends Construct {
})
};

const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([sqsEventTarget]);
// build an event bus if existingEventBus is provided or eventBusProps are provided
this.eventBus = defaults.buildEventBus(this, {
existingEventBusInterface: props.existingEventBusInterface,
eventBusProps: props.eventBusProps
});

const defaultEventsRuleProps = defaults.DefaultEventsRuleProps([sqsEventTarget], this.eventBus);
const eventsRuleProps = overrideProps(defaultEventsRuleProps, props.eventRuleProps, true);

this.eventsRule = new events.Rule(this, 'EventsRule', eventsRuleProps);
Expand Down
Loading

0 comments on commit 60dd243

Please sign in to comment.