Skip to content

Commit

Permalink
feat(sqs): add DLQ readonly property to Queue (aws#18232)
Browse files Browse the repository at this point in the history
feat(@aws-cdk/aws-sqs): add DLQ readonly property

motivation is to be able to read the DLQ properties after the queue as been created. Such as referencing it in a different stack.

aws#18083  
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
markmansur authored and TikiTDO committed Feb 21, 2022
1 parent b35d16c commit 52a280a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 6 additions & 0 deletions packages/@aws-cdk/aws-sqs/lib/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ export class Queue extends QueueBase {
*/
public readonly fifo: boolean;

/**
* If this queue is configured with a dead-letter queue, this is the dead-letter queue settings.
*/
public readonly deadLetterQueue?: DeadLetterQueue;

protected readonly autoCreatePolicy = true;

constructor(scope: Construct, id: string, props: QueueProps = {}) {
Expand Down Expand Up @@ -361,6 +366,7 @@ export class Queue extends QueueBase {
this.queueName = this.getResourceNameAttribute(queue.attrQueueName);
this.encryptionMasterKey = encryptionMasterKey;
this.queueUrl = queue.ref;
this.deadLetterQueue = props.deadLetterQueue;

function _determineEncryptionProps(this: Queue): { encryptionProps: EncryptionProps, encryptionMasterKey?: kms.IKey } {
let encryption = props.encryption || QueueEncryption.UNENCRYPTED;
Expand Down
5 changes: 4 additions & 1 deletion packages/@aws-cdk/aws-sqs/test/sqs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ test('default properties', () => {
test('with a dead letter queue', () => {
const stack = new Stack();
const dlq = new sqs.Queue(stack, 'DLQ');
new sqs.Queue(stack, 'Queue', { deadLetterQueue: { queue: dlq, maxReceiveCount: 3 } });
const dlqProps = { queue: dlq, maxReceiveCount: 3 };
const queue = new sqs.Queue(stack, 'Queue', { deadLetterQueue: dlqProps });

expect(stack).toMatchTemplate({
'Resources': {
Expand All @@ -58,6 +59,8 @@ test('with a dead letter queue', () => {
},
},
});

expect(queue.deadLetterQueue).toEqual(dlqProps);
});

test('message retention period must be between 1 minute to 14 days', () => {
Expand Down

0 comments on commit 52a280a

Please sign in to comment.