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(appsync): deliver event payloads as strings (#2223)
edbramwell95c047722fd6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex b722550e..bef2d23e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,14 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]+### Fixed+- **AppSync Events event payloads**: deliver each WebSocket data frame with a string `event` field, matching observed AWS behavior. HTTP and WebSocket publish batches still produce one frame per event.+- **CloudFront — function status follows publish and association** — `DescribeFunction` and `ListFunctions` reported the `DEVELOPMENT` stage as `UNPUBLISHED` even after `PublishFunction`, so Terraform's `aws_cloudfront_function.status`, which reads that stage, never left `UNPUBLISHED`; once the current development version is published it now reports `UNASSOCIATED`, or `ASSOCIATED` while a distribution's cache behavior references the function, and an `UpdateFunction` makes it `UNPUBLISHED` again until the next publish. Contributed by @fabio-andre-rodrigues.+- **Step Functions — JSONata Fail and Wait fields are evaluated** — a JSONata Fail state raised its `Error` and `Cause` expressions as literal text, a JSONata Wait failed on a `Seconds` expression, ignored a `Timestamp` expression and dropped its `Output` and `Assign`, and JSONPath `ErrorPath`/`CausePath` were ignored; they are now evaluated, with AWS's `States.QueryEvaluationError` or `States.Runtime` for a result of the wrong type, a `Seconds` that is not a non-negative integer and an unparsable `Timestamp`.+- **S3 — presigned URLs keep AWS's time limits under `AUTH=true`** — an `X-Amz-Expires` over 604800 seconds or not a number, or a malformed `X-Amz-Date`, answers 400 `AuthorizationQueryParametersError`, and a URL dated more than 15 minutes ahead answers 403 `AccessDenied` `Request is not yet valid`, where they were served. Contributed by @iot-rocket.+- **Auth — credential failures in the service's protocol** — under `AUTH=true` an unknown, inactive or expired access key answered `UnrecognizedClientException` 403 from every service; it now gets the code, status and `Content-Type` AWS sends for the service's protocol, for example `InvalidClientTokenId` 403 from IAM and SQS, `UnrecognizedClientException` 400 from DynamoDB, `InvalidAccessKeyId` 403 from S3 and `AuthFailure` 401 from EC2. Contributed by @iot-rocket.+### Fixed+- **Step Functions — `ListExecutions` order and pagination** — executions came back oldest first, so `maxResults=1` returned the oldest, and `nextToken` was an offset; they now come back most recent first (running executions by `startDate`, the rest by `stopDate`), the token resumes after the last execution returned so one started between pages is not repeated, an unreadable token answers `InvalidToken` and `maxResults=0` uses the default, as on AWS.### Added- **Managed Service for Apache Flink — control plane** — `kinesisanalyticsv2` applications for the `FLINK-*` runtimes: create, describe, update and delete, start and stop with the model's status transitions, snapshots, CloudWatch logging options and tags, per account and region. Updates bump `ApplicationVersionId` and the `ConditionalToken`, and a stale one returns `ConcurrentModificationException`. CloudFormation creates, updates and deletes `AWS::KinesisAnalyticsV2::Application`, `AWS::KinesisAnalyticsV2::ApplicationCloudWatchLoggingOption` and `AWS::Logs::LogStream`, so a CDK Flink stack deploys. Contributed by @Jolley71717.diff --git a/ministack/services/appsync_events.py b/ministack/services/appsync_events.pyindex 0fa35192..96b72e84 100644--- a/ministack/services/appsync_events.py+++ b/ministack/services/appsync_events.py@@ -970,7 +970,7 @@ async def _fanout_publish(api_id: str, channel: str, events: list) -> tuple[listShared between the HTTP ``POST /event`` handler and the WebSocket ``publish``frame handler so both paths return the same ``(successful, failed)`` shape.- Each outbound frame uses ``"event": [<json-string>]`` per the spec.+ Each outbound frame carries one JSON-encoded string, as observed on AWS."""successful: list = []failed: list = []@@ -991,7 +991,7 @@ async def _fanout_publish(api_id: str, channel: str, events: list) -> tuple[listawait conn["outbox"].put({"type": "data","id": sub_id,- "event": [ev],+ "event": ev,})successful.append({"identifier": identifier, "index": idx})except Exception as e:diff --git a/tests/test_appsync_events.py b/tests/test_appsync_events.pyindex 066a6f0a..9d1fde60 100644--- a/tests/test_appsync_events.py+++ b/tests/test_appsync_events.py@@ -788,9 +788,9 @@ def test_websocket_subscribe_receives_published_event(api):data = _drain_until(ws, lambda f: f.get("type") == "data")assert data is not Noneassert data["id"] == "sub-1"- # Per spec, the `event` field is an ARRAY of JSON-encoded strings.- assert isinstance(data["event"], list)- assert json.loads(data["event"][0]) == {"text": "hi"}+ # AWS delivers one JSON-encoded string per data frame.+ assert isinstance(data["event"], str)+ assert json.loads(data["event"]) == {"text": "hi"}finally:ws.close()@@ -805,7 +805,7 @@ def test_websocket_single_level_wildcard(api):first = _drain_until(ws, lambda f: f.get("type") == "data")assert first is not Noneassert first["id"] == "sub-1"- assert json.loads(first["event"][0]) == "a"+ assert json.loads(first["event"]) == "a"# "/default/room1/child" is a two-segment suffix — should NOT match /default/*_publish_http(api, "/default/room1/child", [json.dumps("nope")])@@ -824,7 +824,7 @@ def test_websocket_unsubscribe_stops_delivery(api):_publish_http(api, "/default/room1", [json.dumps("first")])first = _drain_until(ws, lambda f: f.get("type") == "data")assert first is not None- assert json.loads(first["event"][0]) == "first"+ assert json.loads(first["event"]) == "first"ws.send_json({"type": "unsubscribe", "id": "sub-x"})unsub_ack = _drain_until(ws, lambda f: f.get("type") == "unsubscribe_success")@@ -1006,7 +1006,7 @@ def test_websocket_discovers_resource_region_and_pins_frame_context(monkeypatch)assert data == {"type": "data","id": "sub-regional",- "event": [event],+ "event": event,}await incoming.put({"type": "websocket.disconnect"})@@ -1210,7 +1210,7 @@ def test_fanout_publish_isolates_connections_by_api_id():assert await first_outbox.get() == {"type": "data","id": "sub-first",- "event": [event],+ "event": event,}assert second_outbox.empty()@@ -1249,7 +1249,7 @@ def test_websocket_publish_frame_acks_and_fans_out(api):data = _drain_until(listener, lambda f: f.get("type") == "data")assert data is not Noneassert data["id"] == "sub-listener"- assert json.loads(data["event"][0]) == "over-ws"+ assert json.loads(data["event"]) == "over-ws"finally:publisher.close()listener.close()@@ -1547,3 +1547,39 @@ def test_appsync_events_service_hosts_are_not_s3_virtual_hosts():))assert result is None++[email protected]("transport", ["http", "websocket"])+def test_publish_batch_delivers_individual_event_strings(api, transport):+ listener = _open_subscriber(api)+ publisher = _open_subscriber(api) if transport == "websocket" else None+ events = ['{ "message": "hello" }', '[1, 2]', '"text"']+ try:+ assert _subscribe(listener, "sub-batch", "/default/batch") == {+ "type": "subscribe_success", "id": "sub-batch",+ }+ if publisher is None:+ status, ack = _publish_http(api, "/default/batch", events)+ assert status == 200+ else:+ publisher.send_json({+ "type": "publish", "id": "pub-batch",+ "channel": "/default/batch", "events": events,+ })+ ack = _drain_until(publisher, lambda f: f.get("type") == "publish_success")+ assert ack is not None+ assert len(ack["successful"]) == len(events)+ assert ack["failed"] == []+ received = []+ for _ in events:+ frame = _drain_until(listener, lambda f: f.get("type") == "data")+ assert frame is not None+ assert frame["id"] == "sub-batch"+ assert isinstance(frame["event"], str)+ received.append(frame["event"])+ assert sorted(received) == sorted(events)+ assert _drain_until(listener, lambda f: f.get("type") == "data", timeout=0.2) is None+ finally:+ listener.close()+ if publisher is not None:+ publisher.close()