diff --git a/docs/services/sqs.md b/docs/services/sqs.md index 8026bc1ad2..7c9535a490 100644 --- a/docs/services/sqs.md +++ b/docs/services/sqs.md @@ -101,6 +101,8 @@ aws sqs set-queue-attributes \ `GetQueueAttributes` with `--attribute-names All` returns the set AWS returns for a standard queue: `QueueArn`, `CreatedTimestamp`, `LastModifiedTimestamp`, `ApproximateNumberOfMessages`, `ApproximateNumberOfMessagesNotVisible`, `ApproximateNumberOfMessagesDelayed`, `VisibilityTimeout`, `MaximumMessageSize`, `MessageRetentionPeriod`, `DelaySeconds`, `ReceiveMessageWaitTimeSeconds` and `SqsManagedSseEnabled`. `Policy`, `RedrivePolicy` and `KmsMasterKeyId` appear only once set, and FIFO queues also report `FifoQueue` and `ContentBasedDeduplication`. +A standard queue has no `FifoQueue` attribute: `CreateQueue` refuses one, even `FifoQueue=false`, with `InvalidAttributeName` (`Unknown Attribute FifoQueue.`), as AWS does. An `AWS::SQS::Queue` declaring `FifoQueue: false` fails its stack the same way; leave the property out for a standard queue. + `MaximumMessageSize` defaults to `1048576` bytes, the AWS default and maximum since August 2025, when AWS raised both from `262144`. `CreateQueue` and `SetQueueAttributes` reject values outside 1024 to 1048576 with `InvalidAttributeValue`; raising `FLOCI_SERVICES_SQS_MAX_MESSAGE_SIZE` above the AWS maximum raises that accepted ceiling with it. Lowering the variable below 1048576 only changes the default a new queue receives: the accepted ceiling stays at the AWS maximum, so a queue can still be set to `1048576` explicitly. `DelaySeconds` must be 0 to 900, both on a message and as a queue attribute: `SendMessage` rejects other values with `InvalidParameterValue` (in `SendMessageBatch` only that entry fails), and `CreateQueue` and `SetQueueAttributes` reject them with `InvalidAttributeValue`. diff --git a/src/main/java/io/floci/aws/services/sqs/SqsService.java b/src/main/java/io/floci/aws/services/sqs/SqsService.java index d999226042..fe96b26d6d 100644 --- a/src/main/java/io/floci/aws/services/sqs/SqsService.java +++ b/src/main/java/io/floci/aws/services/sqs/SqsService.java @@ -733,6 +733,10 @@ public class SqsService implements Resettable, ResourceProvider { throw new AwsException("InvalidParameterValue", "The name of a FIFO queue can only end with '.fifo'.", 400); } + if (!hasFifoSuffix && attributes != null && attributes.containsKey("FifoQueue")) { + // A standard queue has no FifoQueue attribute, so SQS refuses even an explicit false. + throw new AwsException("InvalidAttributeName", "Unknown Attribute FifoQueue.", 400); + } if (hasFifoSuffix && !fifoRequested) { // Auto-set FifoQueue attribute when name ends with .fifo attributes = attributes == null ? new HashMap<>() : new HashMap<>(attributes); diff --git a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java index 67b0eb7ba4..b7888b21a7 100644 --- a/src/test/java/io/floci/aws/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/cloudformation/CloudFormationSqsQueuePropertiesIntegrationTest.java @@ -5,10 +5,13 @@ import io.floci.aws.testing.CfnStackWaits; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; +import java.util.List; import java.util.Map; import static io.restassured.RestAssured.given; import static org.awaitility.Awaitility.await; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -27,6 +30,8 @@ class CloudFormationSqsQueuePropertiesIntegrationTest { private static final String NO_VALUE_STACK = "cfn-sqs-queue-no-value"; private static final String SSE_STACK = "cfn-sqs-queue-sse"; private static final String FIFO_STACK = "cfn-sqs-queue-fifo"; + private static final String FIFO_FALSE_STACK = "cfn-sqs-queue-fifo-false"; + private static final String FIFO_NO_VALUE_STACK = "cfn-sqs-queue-fifo-no-value"; @Test void declaredPropertiesReachTheQueueAndDroppedOnesReturnToTheirDefaults() { @@ -222,6 +227,56 @@ class CloudFormationSqsQueuePropertiesIntegrationTest { cloudFormation(FIFO_STACK, "DeleteStack", null); } + @Test + void aStandardQueueDeclaringFifoQueueFalseFailsTheStackAsAwsDoes() { + String template = """ + { + "Resources": { + "Queue": {"Type": "AWS::SQS::Queue", "Properties": {"FifoQueue": false}} + } + } + """; + cloudFormation(FIFO_FALSE_STACK, "CreateStack", template); + + CfnStackWaits.StackState state = CfnStackWaits.awaitTerminal(FIFO_FALSE_STACK, CFN_AUTH); + assertEquals("ROLLBACK_COMPLETE", state.status(), state.reason()); + String events = given() + .contentType("application/x-www-form-urlencoded") + .header("Authorization", CFN_AUTH) + .formParam("Action", "DescribeStackEvents") + .formParam("StackName", FIFO_FALSE_STACK) + .when().post("/").then().statusCode(200).extract().asString(); + List failures = XmlParser.extractGroups(events, "member").stream() + .filter(event -> "Queue".equals(event.get("LogicalResourceId")) + && "CREATE_FAILED".equals(event.get("ResourceStatus"))) + .map(event -> event.get("ResourceStatusReason")) + .toList(); + assertThat(failures, contains(containsString("Unknown Attribute FifoQueue."))); + cloudFormation(FIFO_FALSE_STACK, "DeleteStack", null); + } + + @Test + void aFifoQueueAConditionDropsWithNoValueLeavesAStandardQueue() { + String template = """ + { + "Conditions": {"Fifo": {"Fn::Equals": ["yes", "no"]}}, + "Resources": { + "Queue": { + "Type": "AWS::SQS::Queue", + "Properties": {"FifoQueue": {"Fn::If": ["Fifo", true, {"Ref": "AWS::NoValue"}]}} + } + }, + "Outputs": {"QueueUrl": {"Value": {"Ref": "Queue"}}} + } + """; + cloudFormation(FIFO_NO_VALUE_STACK, "CreateStack", template); + String queueUrl = XmlParser.extractPairs(describeStacks(FIFO_NO_VALUE_STACK, "CREATE_COMPLETE"), "Outputs", + "OutputKey", "OutputValue").get("QueueUrl"); + + assertFalse(queueAttributes(queueUrl).containsKey("FifoQueue")); + cloudFormation(FIFO_NO_VALUE_STACK, "DeleteStack", null); + } + private static void cloudFormation(String stack, String action, String templateBody) { if (templateBody == null) { given() diff --git a/src/test/java/io/floci/aws/services/sqs/SqsFifoQueueAttributeIntegrationTest.java b/src/test/java/io/floci/aws/services/sqs/SqsFifoQueueAttributeIntegrationTest.java new file mode 100644 index 0000000000..51f7da7187 --- /dev/null +++ b/src/test/java/io/floci/aws/services/sqs/SqsFifoQueueAttributeIntegrationTest.java @@ -0,0 +1,34 @@ +package io.floci.aws.services.sqs; + +import io.floci.aws.testing.AwsTestClients; +import io.quarkus.test.junit.QuarkusTest; +import org.junit.jupiter.api.Test; +import software.amazon.awssdk.regions.Region; +import software.amazon.awssdk.services.sqs.SqsClient; +import software.amazon.awssdk.services.sqs.model.InvalidAttributeNameException; +import software.amazon.awssdk.services.sqs.model.QueueAttributeName; +import software.amazon.awssdk.services.sqs.model.QueueDoesNotExistException; + +import java.util.Map; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +/** A standard queue has no FifoQueue attribute, so SQS refuses one even when it says {@code false}. */ +@QuarkusTest +class SqsFifoQueueAttributeIntegrationTest { + + @Test + void aStandardQueueWithFifoQueueFalseIsRefusedAsAnUnknownAttribute() { + String queueName = "standard-" + UUID.randomUUID().toString().substring(0, 8); + try (SqsClient sqs = AwsTestClients.create(SqsClient.builder(), "test", Region.US_EAST_1)) { + InvalidAttributeNameException refused = assertThrows(InvalidAttributeNameException.class, + () -> sqs.createQueue(r -> r.queueName(queueName) + .attributes(Map.of(QueueAttributeName.FIFO_QUEUE, "false")))); + + assertEquals("Unknown Attribute FifoQueue.", refused.awsErrorDetails().errorMessage()); + assertThrows(QueueDoesNotExistException.class, () -> sqs.getQueueUrl(r -> r.queueName(queueName))); + } + } +}