Skip to content

Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.

fix(cloudformation): generate a .fifo queue name for AWS::SQS::Queue with FifoQueue (#1935)

iot-rocket7d15bd2f3b89
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1c13621..1e1d98dd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Fixed
+- **CloudFormation — `AWS::SQS::Queue` with `FifoQueue` gets a generated `.fifo` name** — `FifoQueue: true` without a `QueueName` creates a FIFO queue with a generated `.fifo` name instead of a standard queue, and a `QueueName` whose `.fifo` suffix disagrees with `FifoQueue` fails the resource. Contributed by @iot-rocket.
- **RDS — `DescribeDBClusterSnapshotAttributes`** — was unimplemented (`InvalidAction: Unknown RDS action`), so Terraform's `aws_db_cluster_snapshot` resource failed on read (`reading RDS DB Cluster Snapshot … attribute`) after creating the snapshot. Returns the `restore` attribute with no shared accounts (the manual-snapshot default); `ModifyDBClusterSnapshotAttribute` is not implemented. Unknown snapshot ids answer `DBClusterSnapshotNotFoundFault`.
- **Lambda — Docker executor under `USE_SSL=1` when MiniStack runs in a container** — the gateway certificate, CA bundle and Java truststore were bind-mounted into every Lambda container from MiniStack's own filesystem (`MINISTACK_SSL_CERT`, or the generated `ministack-tls/server.crt` under the temp directory), paths the host Docker daemon cannot see, so every invocation failed with `bind source path does not exist`. In a container they are now copied into the Lambda container, as function code already is.
- **ECS — forced rolling deployments replace tasks and refresh images** — `UpdateService(forceNewDeployment=True)` replaces tasks even when the task definition is unchanged or omitted. Rolling deployments preserve scheduling limits, wait for replacement tasks to stabilize, and retain circuit-breaker rollback; zero-sized deployments drain old tasks and complete. Docker-backed services pin image digests per deployment, honor `versionConsistency: disabled`, and use Secrets Manager credentials for private registries. Tasks report resolved image digests and Fargate platform fields. Cached images remain usable on both launch types, including MiniStack ECR images, preserving MiniStack’s intentional offline fallback.
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 7ccefac1..4e1cdb02 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -1414,9 +1414,23 @@ def _sqs_queue_fields(props, is_fifo):
return fields
+def _sqs_queue_name(props, stack_name, logical_id):
+ """The queue name, which ends in .fifo exactly when FifoQueue is true."""
+ is_fifo = _cfn_bool(props.get("FifoQueue"))
+ name = props.get("QueueName")
+ if not name:
+ name = _physical_name(stack_name, logical_id, max_len=75 if is_fifo else 80)
+ name += ".fifo" if is_fifo else ""
+ elif name.endswith(".fifo") != is_fifo:
+ raise _sqs._Err("InvalidParameterValue", (
+ "The name of a FIFO queue can only include alphanumeric characters, hyphens, or "
+ "underscores, must end with .fifo suffix and be 1 to 80 in length." if is_fifo else
+ "Can only include alphanumeric characters, hyphens, or underscores. 1 to 80 in length"))
+ return name, is_fifo
+
+
def _sqs_create(logical_id, props, stack_name):
- name = props.get("QueueName") or _physical_name(stack_name, logical_id, max_len=80)
- is_fifo = name.endswith(".fifo")
+ name, is_fifo = _sqs_queue_name(props, stack_name, logical_id)
attributes = _sqs_queue_fields(props, is_fifo)
url = _sqs._queue_url_for_account(get_account_id(), name)
arn = f"arn:aws:sqs:{get_region()}:{get_account_id()}:{name}"
@@ -1443,14 +1457,12 @@ def _sqs_create(logical_id, props, stack_name):
def _sqs_update(physical_id, old_props, new_props, stack_name, logical_id=None):
"""Update a queue's attributes in place, keeping its messages.
- QueueName (and the .fifo suffix it implies) is create-only on AWS: a
- change is a replacement, so the new queue is created and the old one
- removed. Everything else maps onto SetQueueAttributes semantics — the
+ QueueName and FifoQueue are create-only on AWS: a change is a
+ replacement, so the new queue is created and the old one removed.
+ Everything else maps onto SetQueueAttributes semantics — the
queue record (URL, messages, dedup state) survives.
"""
- name = new_props.get("QueueName") or _physical_name(
- stack_name, logical_id or physical_id, max_len=80
- )
+ name, _ = _sqs_queue_name(new_props, stack_name, logical_id or physical_id)
queue = _sqs._queues.get(physical_id)
replaced = _rename_replacement(
physical_id, old_props, new_props, stack_name, logical_id,
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index b929c745..babbd6ef 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -18715,6 +18715,54 @@ def test_cfn_sqs_queue_invalid_attribute_fails_the_resource(cfn, sqs, props, par
_delete_cfn_test_stack(cfn, stack_name)
+def test_cfn_sqs_queue_generated_fifo_name(cfn, sqs):
+ """FifoQueue without a QueueName creates a FIFO queue with a .fifo name that an update keeps."""
+ stack_name = f"cfn-sqs-gen-{_uuid_mod.uuid4().hex[:8]}-" + "x" * 70
+
+ def tpl(props):
+ return json.dumps({"Resources": {"Queue": {"Type": "AWS::SQS::Queue", "Properties": {
+ "FifoQueue": True, **props}}}})
+
+ cfn.create_stack(StackName=stack_name, TemplateBody=tpl({}))
+ try:
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "CREATE_COMPLETE", stack.get("StackStatusReason")
+ queue_url = _stack_physical_id(cfn, stack_name, "Queue")
+ name = queue_url.rsplit("/", 1)[1]
+ assert len(name) <= 80 and name.endswith(".fifo")
+ attrs = sqs.get_queue_attributes(QueueUrl=queue_url, AttributeNames=["FifoQueue"])["Attributes"]
+ assert attrs.get("FifoQueue") == "true"
+ cfn.update_stack(StackName=stack_name, TemplateBody=tpl({"VisibilityTimeout": 60}))
+ stack = _wait_stack(cfn, stack_name)
+ assert stack["StackStatus"] == "UPDATE_COMPLETE", stack.get("StackStatusReason")
+ assert _stack_physical_id(cfn, stack_name, "Queue") == queue_url
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
[email protected]("fifo_queue,suffix,message", [
+ (False, ".fifo", "Can only include alphanumeric characters"),
+ (None, ".fifo", "Can only include alphanumeric characters"),
+ (True, "", "The name of a FIFO queue can only include alphanumeric characters"),
+], ids=["false", "unset", "no-suffix"])
+def test_cfn_sqs_queue_name_suffix_must_match_fifo_queue(cfn, sqs, fifo_queue, suffix, message):
+ """A QueueName ending in .fifo needs FifoQueue true, and FifoQueue true needs one."""
+ stack_name = f"cfn-sqs-sfx-{_uuid_mod.uuid4().hex[:8]}"
+ props = {"QueueName": f"{stack_name}-q{suffix}"}
+ if fifo_queue is not None:
+ props["FifoQueue"] = fifo_queue
+ cfn.create_stack(StackName=stack_name, TemplateBody=json.dumps(_sqs_dlq_tpl(props)))
+ try:
+ assert _wait_stack(cfn, stack_name)["StackStatus"] == "ROLLBACK_COMPLETE"
+ failed = [e for e in cfn.describe_stack_events(StackName=stack_name)["StackEvents"]
+ if e["LogicalResourceId"] == "Queue" and e["ResourceStatus"] == "CREATE_FAILED"]
+ assert failed and message in failed[0]["ResourceStatusReason"]
+ with pytest.raises(ClientError):
+ sqs.get_queue_url(QueueName=props["QueueName"])
+ finally:
+ _delete_cfn_test_stack(cfn, stack_name)
+
+
def test_cfn_update_logs_log_group_in_place(cfn, logs):
"""A log group's retention updates in place; its streams survive."""
suffix = _uuid_mod.uuid4().hex[:8]