-
Notifications
You must be signed in to change notification settings - Fork 250
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(aww-eventbridge-sqs): add a dlq for the event rule #1253
Changes from 4 commits
4613c8e
9ea4800
b7d4ae1
6ffc429
cd1d571
628acd8
7bfdaca
4d409e1
e705f3b
3af5e89
99082a4
e99be92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
import * as sqs from 'aws-cdk-lib/aws-sqs'; | ||
import * as events from 'aws-cdk-lib/aws-events'; | ||
import * as eventtargets from 'aws-cdk-lib/aws-events-targets'; | ||
import * as kms from 'aws-cdk-lib/aws-kms'; | ||
import * as defaults from '@aws-solutions-constructs/core'; | ||
import { ServicePrincipal } from 'aws-cdk-lib/aws-iam'; | ||
|
@@ -42,6 +43,15 @@ export interface EventbridgeToSqsProps { | |
* @default - None | ||
*/ | ||
readonly eventRuleProps: events.RuleProps; | ||
/** | ||
* Whether to deploy a DLQ for the Rule itself | ||
* (this DLQ is would receive messages that can't be delivered to | ||
* the target SQS queue)) | ||
* | ||
* This is new, so defaulting to false to avoid surprising existing clients | ||
* @default - false | ||
*/ | ||
readonly deployRuleDlq?: boolean; | ||
/** | ||
* Existing instance of SQS queue object, providing both this and queueProps will cause an error. | ||
* | ||
|
@@ -105,6 +115,7 @@ export class EventbridgeToSqs extends Construct { | |
public readonly eventBus?: events.IEventBus; | ||
public readonly eventsRule: events.Rule; | ||
public readonly encryptionKey?: kms.IKey; | ||
public readonly eventRuleDlq?: sqs.Queue; | ||
|
||
/** | ||
* @summary Constructs a new instance of the EventbridgeToSqs class. | ||
|
@@ -140,12 +151,19 @@ export class EventbridgeToSqs extends Construct { | |
this.encryptionKey = buildQueueResponse.key; | ||
this.deadLetterQueue = buildQueueResponse.dlq; | ||
|
||
const sqsEventTarget: events.IRuleTarget = { | ||
bind: () => ({ | ||
id: this.sqsQueue.queueName, | ||
arn: this.sqsQueue.queueArn | ||
}) | ||
}; | ||
let sqsEventTargetProps: eventtargets.SqsQueueProps = {}; | ||
|
||
if (defaults.CheckBooleanWithDefault(props.deployRuleDlq, false)) { | ||
this.eventRuleDlq = defaults.buildQueue(this, 'ruleDlq', { | ||
deployDeadLetterQueue: false, | ||
enableEncryptionWithCustomerManagedKey: enableEncryptionParam, | ||
encryptionKey: this.encryptionKey, | ||
}).queue; | ||
|
||
sqsEventTargetProps = defaults.consolidateProps(sqsEventTargetProps, { deadLetterQueue: this.eventRuleDlq }); | ||
} | ||
|
||
const sqsEventTarget = new eventtargets.SqsQueue(this.sqsQueue, sqsEventTargetProps); | ||
|
||
// build an event bus if existingEventBus is provided or eventBusProps are provided | ||
this.eventBus = defaults.buildEventBus(this, { | ||
|
@@ -163,7 +181,5 @@ export class EventbridgeToSqs extends Construct { | |
this.sqsQueue.grantPurge(new ServicePrincipal('events.amazonaws.com')); | ||
} | ||
|
||
// Policy for event to be able to send messages to the queue and Grant Event Bridge service access to the SQS queue encryption key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's allowing events to be sent to the queue now without this in there anymore? (Mostly curious but wanted to point it out just in case too) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a new aws-event-targets library since we first wrote this, the SqsQueue target object adds the permissions automatically. It doesn't add Purge however. |
||
this.sqsQueue.grantSendMessages(new ServicePrincipal('events.amazonaws.com')); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"version":"36.0.0"} | ||
{"version":"39.0.0"} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"version": "36.0.0", | ||
"version": "39.0.0", | ||
"testCases": { | ||
"evtsqs-exist-bus/Integ/DefaultTest": { | ||
"stacks": [ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Proposing this language for the property description:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done