From a9d3b02783104fe862a3e863e8c89af845b49c8c Mon Sep 17 00:00:00 2001 From: Rico Hermans Date: Mon, 28 Oct 2024 19:55:27 +0100 Subject: [PATCH] fix(sqs): queue with `fifo: false` does not deploy (#31922) The `FifoQueue` property in CloudFormation can only be `true`, or must be absent. If you pass `FifoQueue: false`, you will receive the following error: ``` Resource handler returned message: "Unknown Attribute FifoQueue. (Service: Sqs, Status Code: 400, Request ID: e27d9d99-fe35-5b36-b670-c200419bc975)" (RequestToken: 1d882ab3-52e8-7e4b-e2d3-58e6ba10141d, HandlerErrorCode: InvalidRequest) ``` Make it so that a `fifo: false` configuration doesn't output FifoQueue at all. Closes #8550. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/aws-cdk-lib/aws-sqs/lib/queue.ts | 6 ++++- packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts index e0e5503c3704c..d05f886cc22a8 100644 --- a/packages/aws-cdk-lib/aws-sqs/lib/queue.ts +++ b/packages/aws-cdk-lib/aws-sqs/lib/queue.ts @@ -560,7 +560,11 @@ export class Queue extends QueueBase { contentBasedDeduplication: props.contentBasedDeduplication, deduplicationScope: props.deduplicationScope, fifoThroughputLimit: props.fifoThroughputLimit, - fifoQueue, + + // This value will be passed directly into the L1 props, but the underlying `AWS::SQS::Queue` + // does not accept `FifoQueue: false`. It must either be `true` or absent. So change a `false` into + // an `undefined`. + fifoQueue: fifoQueue ? true : undefined, }; } diff --git a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts index 0ae7bc2919ef5..690eb0ec275be 100644 --- a/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts +++ b/packages/aws-cdk-lib/aws-sqs/test/sqs.test.ts @@ -675,6 +675,28 @@ test('test a queue throws when deduplicationScope specified on non fifo queue', }).toThrow(); }); +test('fifo: false is dropped from properties', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + new sqs.Queue(stack, 'Queue', { + fifo: false, + }); + + // THEN + Template.fromStack(stack).templateMatches({ + 'Resources': { + 'Queue4A7E3555': { + 'Type': 'AWS::SQS::Queue', + 'Properties': Match.absent(), + 'UpdateReplacePolicy': 'Delete', + 'DeletionPolicy': 'Delete', + }, + }, + }); +}); + test('test metrics', () => { // GIVEN const stack = new Stack();