Skip to content

Commit aa8484a

Browse files
authored
fix(sqs): redrivePermission is set to byQueue no matter what value is specified (#29130)
### Issue #29129 Closes #29129. ### Reason for this change When `redriveAllowPolicy.redrivePermission` is specified, any value will be output to template as `byQueue` ### Description of changes 1. Fix the evaluation order by enclosing the ternary operators in parentheses ```typescript ?? (props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL), ``` 2. Added a test case in `packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts` when redrivePermission is specified other than `BY_QUEUE`. 3. Added an integ test case in `packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts` ### Description of how you validated changes Added a test case in `packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts` when redrivePermission is specified other than `BY_QUEUE`. Added an integ test case in `packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts` And ran the test case. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9156b13 commit aa8484a

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.js.snapshot/aws-cdk-sqs.template.json

+10
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
"Resources": {
33
"SourceQueue1F4BBA4BB": {
44
"Type": "AWS::SQS::Queue",
5+
"Properties": {
6+
"RedriveAllowPolicy": {
7+
"redrivePermission": "allowAll"
8+
}
9+
},
510
"UpdateReplacePolicy": "Delete",
611
"DeletionPolicy": "Delete"
712
},
813
"SourceQueue22481CB5A": {
914
"Type": "AWS::SQS::Queue",
15+
"Properties": {
16+
"RedriveAllowPolicy": {
17+
"redrivePermission": "denyAll"
18+
}
19+
},
1020
"UpdateReplacePolicy": "Delete",
1121
"DeletionPolicy": "Delete"
1222
},

Diff for: packages/@aws-cdk-testing/framework-integ/test/aws-sqs/test/integ.sqs-source-queue-permission.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,16 @@ const app = new App();
77

88
const stack = new Stack(app, 'aws-cdk-sqs');
99

10-
const sourceQueue1 = new Queue(stack, 'SourceQueue1');
11-
const sourceQueue2 = new Queue(stack, 'SourceQueue2');
10+
const sourceQueue1 = new Queue(stack, 'SourceQueue1', {
11+
redriveAllowPolicy: {
12+
redrivePermission: RedrivePermission.ALLOW_ALL,
13+
},
14+
});
15+
const sourceQueue2 = new Queue(stack, 'SourceQueue2', {
16+
redriveAllowPolicy: {
17+
redrivePermission: RedrivePermission.DENY_ALL,
18+
},
19+
});
1220

1321
new Queue(stack, 'DeadLetterQueue', {
1422
redriveAllowPolicy: {

Diff for: packages/aws-cdk-lib/aws-sqs/lib/queue.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ export class Queue extends QueueBase {
411411
redrivePermission: props.redriveAllowPolicy.redrivePermission
412412
// When `sourceQueues` is provided in `redriveAllowPolicy`, `redrivePermission` defaults to allow specified queues (`BY_QUEUE`);
413413
// otherwise, it defaults to allow all queues (`ALLOW_ALL`).
414-
?? props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL,
414+
?? (props.redriveAllowPolicy.sourceQueues ? RedrivePermission.BY_QUEUE : RedrivePermission.ALLOW_ALL),
415415
sourceQueueArns: props.redriveAllowPolicy.sourceQueues?.map(q => q.queueArn),
416416
} : undefined;
417417

Diff for: packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,33 @@ describe('redriveAllowPolicy', () => {
753753
});
754754
});
755755

756+
test.each([
757+
[sqs.RedrivePermission.ALLOW_ALL, 'allowAll'],
758+
[sqs.RedrivePermission.DENY_ALL, 'denyAll'],
759+
])('redrive permission can be set to %s', (permission, expected) => {
760+
const stack = new Stack();
761+
new sqs.Queue(stack, 'Queue', {
762+
redriveAllowPolicy: {
763+
redrivePermission: permission,
764+
},
765+
});
766+
767+
Template.fromStack(stack).templateMatches({
768+
'Resources': {
769+
'Queue4A7E3555': {
770+
'Type': 'AWS::SQS::Queue',
771+
'Properties': {
772+
'RedriveAllowPolicy': {
773+
'redrivePermission': expected,
774+
},
775+
},
776+
'UpdateReplacePolicy': 'Delete',
777+
'DeletionPolicy': 'Delete',
778+
},
779+
},
780+
});
781+
});
782+
756783
test('explicit specification of dead letter source queues', () => {
757784
const stack = new Stack();
758785
const sourceQueue1 = new sqs.Queue(stack, 'SourceQueue1');

0 commit comments

Comments
 (0)