Ministack: Free, open-source local AWS emulator - 60+ services, Terraform compatible, real databases. Free forever. MIT licensed.
Python awsaws-emulatoraws-localaws-sdkdevtoolsdockerdynamodbec2emulatorlambdalocalstacklocalstack-alternativeministackmock-awsopen-sourcepythons3sqsterraform
fix(sqs): QueueUrl follows the gateway's TLS scheme (#1891)
Jeff Heller2b237d2760cb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 83202148..8b4a513c 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).### Fixed+- **SQS — `QueueUrl` matches the gateway's TLS scheme (`USE_SSL=1`)** — `CreateQueue`/`GetQueueUrl`/`ListQueues` always returned `http://` URLs, and the AWS SDK v3 uses the QueueUrl itself as the request endpoint (`useQueueUrlAsEndpoint` defaults true), so a client handed that URL left the TLS-only gateway. The `AWS::SQS::Queue` CloudFormation provisioner built the same hardcoded scheme and now reuses the shared helper.- **API Gateway v2 (HTTP API) — an unmatched route answers AWS's exact 404 body** — a request with no matching route answered `{"message": "No route found"}`; AWS answers `{"message":"Not Found"}` (compact JSON, no space after the colon). REST API (v1) is unaffected — it already answers a route miss with its own `403 MISSING_AUTHENTICATION_TOKEN` gateway response, not this literal.- **API Gateway v2 — `apiEndpoint` follows the gateway's TLS scheme** — with `USE_SSL=1` the gateway listener serves only HTTPS, but CreateApi and the `AWS::ApiGatewayV2::Api` CloudFormation resource always returned an `http://` `apiEndpoint`, which nothing answers. They now return `https://`, or `wss://` for a WebSocket API, as AWS does. Without `USE_SSL` the endpoint keeps `http://`.diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.pyindex f1ddbea5..46055e3a 100644--- a/ministack/services/cloudformation/provisioners.py+++ b/ministack/services/cloudformation/provisioners.py@@ -1387,7 +1387,7 @@ 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")attributes = _sqs_queue_fields(props, is_fifo)- url = f"http://{_sqs.DEFAULT_HOST}:{_sqs.DEFAULT_PORT}/{get_account_id()}/{name}"+ url = _sqs._queue_url_for_account(get_account_id(), name)arn = f"arn:aws:sqs:{get_region()}:{get_account_id()}:{name}"now_ts = str(int(time.time()))attributes.update(QueueArn=arn, CreatedTimestamp=now_ts, LastModifiedTimestamp=now_ts)diff --git a/ministack/services/sqs.py b/ministack/services/sqs.pyindex 3acfc3c2..969f7294 100644--- a/ministack/services/sqs.py+++ b/ministack/services/sqs.py@@ -40,6 +40,7 @@ from xml.sax.saxutils import escape as _escfrom ministack.core.arn import ArnParseError, parse_arnfrom ministack.core.responses import AccountRegionScopedDict, get_account_id, get_region, new_uuid+from ministack.core.tls import use_ssl_enabledlogger = logging.getLogger("sqs")@@ -252,7 +253,8 @@ def _queue_url(name: str) -> str:def _queue_url_for_account(account_id: str, name: str) -> str:- return f"http://{DEFAULT_HOST}:{DEFAULT_PORT}/{account_id}/{name}"+ scheme = "https" if use_ssl_enabled() else "http"+ return f"{scheme}://{DEFAULT_HOST}:{DEFAULT_PORT}/{account_id}/{name}"def _queue_name_from_arn_spec(spec) -> str | None:diff --git a/tests/test_sqs.py b/tests/test_sqs.pyindex 0624d149..7179ca21 100644--- a/tests/test_sqs.py+++ b/tests/test_sqs.py@@ -2254,3 +2254,39 @@ class TestAuthDisabledIsPermissive:assert _resp_code(_as(ACCT_A, sns_svc._publish, {"TopicArn": topic, "Message": "open"})) == (200, "")assert len(_queue_bodies(qarn)) == 1+++def test_queue_url_scheme_https_when_tls(monkeypatch):+ """With USE_SSL=1 the gateway serves TLS, so QueueUrl must be https —+ the AWS SDK v3 uses the QueueUrl itself as the request endpoint+ (useQueueUrlAsEndpoint defaults true), so an http:// QueueUrl would+ leave the TLS-only gateway."""+ monkeypatch.setenv("USE_SSL", "1")+ name = _uniq("tls-scheme")+ created = _as(ACCT_A, sqs_svc._act_create_queue, {"QueueName": name}, "")["QueueUrl"]+ assert created.startswith("https://"), created++ looked_up = _as(ACCT_A, sqs_svc._act_get_queue_url, {"QueueName": name}, "")["QueueUrl"]+ assert looked_up.startswith("https://"), looked_up++ # A request using the returned https URL resolves the same queue.+ q = _as(ACCT_A, sqs_svc._get_q, created)+ assert q["name"] == name+++def test_cfn_sqs_queue_url_scheme_https_when_tls(monkeypatch):+ """The AWS::SQS::Queue provisioner builds the same QueueUrl as CreateQueue."""+ from ministack.services.cloudformation import provisioners++ monkeypatch.setenv("USE_SSL", "1")+ name = _uniq("cfn-tls-scheme")+ url, _attrs = provisioners._sqs_create("Queue", {"QueueName": name}, "stack")+ assert url.startswith("https://"), url+++def test_queue_url_scheme_http_without_tls(monkeypatch):+ """Without TLS the QueueUrl keeps http (existing behaviour)."""+ monkeypatch.delenv("USE_SSL", raising=False)+ name = _uniq("plain-scheme")+ created = _as(ACCT_A, sqs_svc._act_create_queue, {"QueueName": name}, "")["QueueUrl"]+ assert created.startswith("http://"), created