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(sfn): putEvents publish to EB (#1446)
Nahuel Nuceraab6cf2fa0726
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex febff1f5..b557c077 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **CloudFormation — API Gateway (v1) API keys and usage plans** — `AWS::ApiGateway::ApiKey`, `AWS::ApiGateway::UsagePlan`, and `AWS::ApiGateway::UsagePlanKey` failed stack creation with `Unsupported resource type`, even though the runtime `CreateApiKey` / `CreateUsagePlan` APIs were already served. The three resource types now provision through those same stores: an `ApiKey` supports a pinned `Value`, `Enabled`, and `StageKeys`, updates `Name` / `Description` / `Enabled` in place, and exposes both `Ref` and `Fn::GetAtt APIKeyId` as the key id; a `UsagePlan` maps `Throttle` / `Quota` / `ApiStages` and returns its id via `Ref` and `Fn::GetAtt Id`; a `UsagePlanKey` associates a key with a plan and is torn down from the plan on delete. This unblocks CDK `RestApi` / `ApiKey` constructs and Terraform `aws_api_gateway_api_key` deployed through CloudFormation. Contributed by @ryan-bennett.- **AWS IoT Jobs — control plane and device data plane** — `CreateJob` fell through to `Unsupported IoT path` and the `iot-jobs-data` endpoint did not exist, so device OTA loops could not be rehearsed locally. The `iot` service now serves the nine job operations and a new `iot-jobs-data` service the four device ones (incl. the `$next` sentinel), sharing one store and the AWS execution state machine. A `documentSource` job gets a placeholder, not the S3 object. Contributed by @iot-rocket.### Fixed+- **Step Functions — `arn:aws:states:::events:putEvents` actually publishes the event** — the optimized EventBridge integration fell through to the task passthrough, so the state reported `SUCCEEDED` while nothing reached any rule target. It now calls EventBridge `PutEvents` and returns its response (`Entries` / `FailedEntryCount`). Reported by @iwasakar.- **Aurora DSQL — `SELECT ... FOR UPDATE` is no longer refused for its predicate** — strict mode enforced a rule Aurora DSQL does not (any more): a locking read had to be a single table with an equality on every primary key column, or it was rejected with `0A000` "locking clause such as FOR UPDATE can be applied only on tables with equality predicates on the key". The check compared the WHERE clause's column against the key name as raw SQL text, so `WHERE "id" = $1` did not match key column `id` — and every mainstream ORM (Drizzle, Prisma, TypeORM, SQLAlchemy) quotes its identifiers, so in practice every locking read from an ORM failed, with a message that blamed the user's schema. Measured against a live cluster (eu-central-1, 2026-08-18, `server_version` 16.15), DSQL restricts the lock *strength*, not the predicate: `FOR UPDATE` locks whatever the query selects — no `WHERE` clause, a non-key column, an inequality, `IN`/`OR`, a join, or a table with no primary key all succeed, as do `NOWAIT`, `SKIP LOCKED` and `OF` — while `FOR NO KEY UPDATE`, `FOR SHARE` and `FOR KEY SHARE` are refused with `0A000` "locking clauses other than FOR UPDATE/FOR KEY SHARE are not supported", inside a CTE or subquery included. The predicate rule is gone and the lock-strength rule takes its place, so the emulator stops failing correct code and starts failing the code DSQL actually fails. The new rule is token-based (`FOR SHARE` inside a string literal is text, not a clause) and needs no catalog probe, so a locking read no longer costs a round-trip before it is forwarded.- **Aurora DSQL — quoted identifiers are normalized the way the server stores them** — `ALTER TABLE ... DROP COLUMN` compared the column against the primary key case-insensitively after stripping quotes, so `DROP COLUMN "ID"` was read as key column `id` and refused, while the primary-key probe dropped the quotes from its relation name — `"myschema".t` became `myschema".t` and resolved to nothing, and a table created as `"MyTable"` case-folded to `mytable` and was not found, silently disabling the rule. Identifiers are now folded as PostgreSQL folds them (bare to lower case, quoted verbatim, `""` unescaped) and the relation is requoted part by part before the lookup, so schema-qualified and mixed-case names resolve.- **CloudFormation — `AWS::IoT::Policy` updates apply instead of rolling the stack back** — the type had a create and a delete but no update handler, so a stack update fell through to create, hit `ResourceAlreadyExistsException` on the policy it had provisioned itself, and rolled back with the document unchanged: an IoT policy could be deployed once and never edited again. A changed `PolicyDocument` is now a no-interruption update stored as a new policy version and made the default, so `Ref` keeps naming the same policy and `GetPolicy` returns the new document; a changed `PolicyName` is a replacement, creating the policy under the new name and removing the old one. Because IoT caps a policy at five versions, the update prunes the oldest non-default versions before storing a new document, as the CloudFormation handler does on AWS.diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex 39abb0ac..80f72338 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -5687,9 +5687,33 @@ def _invoke_aws_sdk_integration(resource, input_data):)+def _invoke_events_put_events(resource, input_data):+ """arn:aws:states:::events:putEvents — actually publish to EventBridge.++ Without this the task fell through to the passthrough at the end of+ _invoke_resource: it reported SUCCEEDED but never delivered the event, so a+ state machine that emits notifications completed green while the target+ never fired.+ """+ try:+ from ministack.services import eventbridge+ except ImportError:+ logger.warning("eventbridge module unavailable; returning passthrough")+ return input_data+ status, _, body = eventbridge._put_events(input_data)+ result = json.loads(body) if body else {}+ if status >= 400:+ raise _ExecutionError(+ result.get("__type", "EventBridge.EventBridgeException"),+ result.get("message", ""),+ )+ return result++_SERVICE_DISPATCH = {"arn:aws:states:::sqs:sendMessage": _invoke_sqs_send_message,"arn:aws:states:::sns:publish": _invoke_sns_publish,+ "arn:aws:states:::events:putEvents": _invoke_events_put_events,"arn:aws:states:::dynamodb:putItem": lambda r, d: _invoke_dynamodb("putItem", d),"arn:aws:states:::dynamodb:getItem": lambda r, d: _invoke_dynamodb("getItem", d),"arn:aws:states:::dynamodb:deleteItem": lambda r, d: _invoke_dynamodb(diff --git a/tests/conftest.py b/tests/conftest.pyindex 3a96c57e..2ec15b5e 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -172,6 +172,10 @@ _SERIAL_TESTS = {"tests/test_iot_data.py::test_iot_rule_where_topic_function_under_basic_ingest","tests/test_iot_data.py::test_iot_rule_where_or_clause_dispatches_either_branch","tests/test_iot_data.py::test_iot_jitr_registration_event_drives_a_topic_rule",+ # IoT Jobs data-plane routing test: a raw urllib GET with the advertised+ # `{prefix}.jobs.iot.{region}` Host and a tight 5s timeout, so cross-file+ # xdist pressure on the shared event loop makes it time out at random.+ "tests/test_iot_jobs.py::test_iot_jobs_advertised_endpoint_host_reaches_the_data_plane",# WS/MQTT-broker tests (MQTT-over-WebSocket connect/publish/subscribe,# device shadows over MQTT, fleet-index connectivity). They drive the# single-event-loop broker over real WebSocket connections with tightdiff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.pyindex c3285663..15b30f94 100644--- a/tests/test_stepfunctions.py+++ b/tests/test_stepfunctions.py@@ -3041,6 +3041,59 @@ def test_sfn_integration_sqs_send_message(sfn, sqs):assert len(msgs.get("Messages", [])) == 1assert msgs["Messages"][0]["Body"] == "hello from sfn"+def test_sfn_integration_events_put_events(sfn, eb, sqs):+ """Task state publishes to EventBridge via arn:aws:states:::events:putEvents,+ and the event is actually delivered to a rule target — not a silent no-op+ that reports SUCCEEDED while nothing fires (#1443)."""+ import time as _time+ queue_url = sqs.create_queue(QueueName="sfn-events-target")["QueueUrl"]+ queue_arn = sqs.get_queue_attributes(+ QueueUrl=queue_url, AttributeNames=["QueueArn"])["Attributes"]["QueueArn"]+ eb.put_rule(Name="sfn-events-rule",+ EventPattern=json.dumps({"source": ["sfn.pipeline"]}))+ eb.put_targets(Rule="sfn-events-rule", Targets=[{"Id": "1", "Arn": queue_arn}])++ definition = json.dumps({+ "StartAt": "Emit",+ "States": {+ "Emit": {+ "Type": "Task",+ "Resource": "arn:aws:states:::events:putEvents",+ "Parameters": {+ "Entries": [{+ "Source": "sfn.pipeline",+ "DetailType": "test",+ "Detail": "{\"k\": \"v\"}",+ }]+ },+ "End": True,+ },+ },+ })+ sm = sfn.create_state_machine(+ name="sfn-events-integ", definition=definition,+ roleArn="arn:aws:iam::000000000000:role/R")+ ex = sfn.start_execution(stateMachineArn=sm["stateMachineArn"], input="{}")+ desc = _wait_sfn(sfn, ex["executionArn"])+ assert desc["status"] == "SUCCEEDED"+ output = json.loads(desc["output"])+ # A passthrough no-op would echo the input {"Entries": [...]}; the real+ # integration returns the PutEvents response.+ assert output["FailedEntryCount"] == 0+ assert output["Entries"][0]["EventId"]++ # The event must actually reach the rule's target.+ got = None+ for _ in range(20):+ msgs = sqs.receive_message(QueueUrl=queue_url, MaxNumberOfMessages=1,+ WaitTimeSeconds=1)+ if msgs.get("Messages"):+ got = msgs["Messages"][0]["Body"]+ break+ _time.sleep(0.2)+ assert got is not None, "event was not delivered to the EventBridge target"+ assert "sfn.pipeline" in got+def test_sfn_integration_sqs_send_message_wait_for_task_token(sfn, sqs):"""sqs:sendMessage.waitForTaskToken must actually deliver the message(carrying the task token, serialised to JSON) and resume on