Skip to content

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

feat: add generic aws-sdk:* task dispatcher for Step Functions service integrations (#168)

Jay Janssen9d1c1a612b4e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58cf86dc..731cffdf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,17 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [Unreleased]
+
+### Added
+- **Step Functions generic `aws-sdk:*` task dispatcher** — Task states can now use `arn:aws:states:::aws-sdk:<service>:<action>` resources to call any JSON-protocol MiniStack service (DynamoDB, SecretsManager, SSM, Logs, Kinesis, Glue, Athena, ECS, ECR, KMS, EventBridge). Query/REST services return clear "not yet supported" errors
+- **Step Functions sync execution error details** — `StartSyncExecution` now returns `error` and `cause` fields for failed executions, matching AWS SFN behaviour
+
+### Tests
+- 3 new tests: SecretsManager round-trip via aws-sdk, DynamoDB round-trip via aws-sdk, unknown service error handling
+
+---
+
## [1.1.46] — 2026-04-07
### Added
@@ -22,7 +33,6 @@ Versioning follows [Semantic Versioning](https://semver.org/).
- 3 EBS tests: snapshot_attribute, volume_attribute, volumes_modifications. Contributed by @mvanhorn (#163)
---
-
## [1.1.45] — 2026-04-07
### Added
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index b357311e..3e94467c 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -513,7 +513,7 @@ def _start_sync_execution(data):
_run_execution(exec_arn)
execution = _executions[exec_arn]
- return json_response({
+ resp = {
"executionArn": exec_arn,
"stateMachineArn": sm_arn,
"name": name,
@@ -524,7 +524,18 @@ def _start_sync_execution(data):
"inputDetails": {"included": True},
"output": execution.get("output") or "{}",
"outputDetails": {"included": True},
- })
+ }
+ # Include error/cause for failed executions (matches AWS SFN behaviour)
+ if execution["status"] == "FAILED":
+ failed_events = [
+ e for e in execution.get("events", [])
+ if e.get("type") == "ExecutionFailed"
+ ]
+ if failed_events:
+ details = failed_events[-1].get("executionFailedEventDetails", {})
+ resp["error"] = details.get("error", "")
+ resp["cause"] = details.get("cause", "")
+ return json_response(resp)
def _describe_state_machine_for_execution(data):
@@ -1209,6 +1220,10 @@ def _invoke_resource(resource, input_data):
if clean.startswith(prefix):
return handler(resource, input_data)
+ # Generic aws-sdk:* service integration
+ if "aws-sdk:" in resource:
+ return _invoke_aws_sdk_integration(resource, input_data)
+
return input_data
@@ -2084,6 +2099,127 @@ def _pascal_to_camel(d):
return out
+# ---------------------------------------------------------------------------
+# Generic aws-sdk:* task dispatcher
+# ---------------------------------------------------------------------------
+
+# Map aws-sdk service names to MiniStack internal routing info.
+# service_key overrides the key used in app.SERVICE_HANDLERS when it differs
+# from the sdk service name.
+_AWS_SDK_SERVICE_MAP = {
+ # JSON-protocol services: use X-Amz-Target header
+ "dynamodb": {"target_prefix": "DynamoDB_20120810", "protocol": "json"},
+ "secretsmanager": {"target_prefix": "secretsmanager", "protocol": "json"},
+ "sfn": {"target_prefix": "AWSStepFunctions", "protocol": "json", "service_key": "states"},
+ "logs": {"target_prefix": "Logs_20140328", "protocol": "json"},
+ "ssm": {"target_prefix": "AmazonSSM", "protocol": "json"},
+ "eventbridge": {"target_prefix": "AWSEvents", "protocol": "json", "service_key": "events"},
+ "kinesis": {"target_prefix": "Kinesis_20131202", "protocol": "json"},
+ "glue": {"target_prefix": "AWSGlue", "protocol": "json"},
+ "athena": {"target_prefix": "AmazonAthena", "protocol": "json"},
+ "ecs": {"target_prefix": "AmazonEC2ContainerServiceV20141113", "protocol": "json"},
+ "ecr": {"target_prefix": "AmazonEC2ContainerRegistry_V20150921", "protocol": "json"},
+ "kms": {"target_prefix": "TrentService", "protocol": "json"},
+ # Query-protocol services (not yet supported via aws-sdk dispatcher)
+ "sqs": {"protocol": "query"},
+ "sns": {"protocol": "query"},
+ "rds": {"protocol": "query"},
+ "elasticache": {"protocol": "query"},
+ "ec2": {"protocol": "query"},
+ "iam": {"protocol": "query"},
+ "sts": {"protocol": "query"},
+ "cloudwatch": {"protocol": "query", "service_key": "monitoring"},
+ # REST services (not yet supported via aws-sdk dispatcher)
+ "s3": {"protocol": "rest"},
+ "lambda": {"protocol": "rest"},
+}
+
+
+def _dispatch_aws_sdk_json(service_info, service_name, action, input_data):
+ """Dispatch an aws-sdk integration call to a JSON-protocol MiniStack service."""
+ from ministack import app
+
+ target_prefix = service_info["target_prefix"]
+ target = f"{target_prefix}.{action}"
+ service_key = service_info.get("service_key", service_name)
+
+ handler = app.SERVICE_HANDLERS.get(service_key)
+ if not handler:
+ raise _ExecutionError(
+ "States.Runtime",
+ f"Service '{service_key}' is not available in MiniStack",
+ )
+
+ body = json.dumps(input_data)
+ headers = {
+ "x-amz-target": target,
+ "content-type": "application/x-amz-json-1.0",
+ "host": f"{service_key}.{REGION}.amazonaws.com",
+ "authorization": (
+ f"AWS4-HMAC-SHA256 Credential=test/20260101/{REGION}/{service_key}/aws4_request"
+ ),
+ }
+
+ # Service handlers are async def but perform no real I/O, so we can
+ # drive the coroutine synchronously — this avoids conflicts with the
+ # already-running uvicorn event loop.
+ coro = handler("POST", "/", headers, body, {})
+ try:
+ coro.send(None)
+ except StopIteration as stop:
+ status, resp_headers, resp_body = stop.value
+ else:
+ # If the coroutine didn't finish in one step it truly needs async;
+ # fall back to the event loop (only reachable if a handler awaits).
+ coro.close()
+ loop = asyncio.new_event_loop()
+ try:
+ status, resp_headers, resp_body = loop.run_until_complete(
+ handler("POST", "/", headers, body, {})
+ )
+ finally:
+ loop.close()
+
+ decoded = resp_body.decode("utf-8") if isinstance(resp_body, bytes) else resp_body
+ result = json.loads(decoded) if decoded else {}
+
+ if status >= 400:
+ error_type = result.get("__type", result.get("Error", {}).get("Code", f"{service_name}.ServiceException"))
+ error_msg = result.get("message", result.get("Message", str(result)))
+ raise _ExecutionError(error_type, error_msg)
+
+ return result
+
+
+def _invoke_aws_sdk_integration(resource, input_data):
+ """Dispatch arn:aws:states:::aws-sdk:<service>:<action> to the target MiniStack service."""
+ # Parse service and action from ARN
+ parts = resource.replace(".sync", "").replace(".waitForTaskToken", "").split(":")
+ # arn:aws:states:::aws-sdk:<service>:<action>
+ # parts after split: ['arn', 'aws', 'states', '', '', 'aws-sdk', '<service>', '<action>']
+ if len(parts) < 8 or parts[5] != "aws-sdk":
+ raise _ExecutionError("States.Runtime", f"Invalid aws-sdk resource ARN: {resource}")
+ service_name = parts[6].lower()
+ action = parts[7]
+
+ service_info = _AWS_SDK_SERVICE_MAP.get(service_name)
+ if not service_info:
+ raise _ExecutionError(
+ "States.Runtime",
+ f"Service '{service_name}' is not supported in MiniStack aws-sdk integrations",
+ )
+
+ protocol = service_info["protocol"]
+ if protocol != "json":
+ raise _ExecutionError(
+ "States.Runtime",
+ f"aws-sdk integration for {protocol}-protocol service '{service_name}' "
+ "is not yet implemented; use native service integrations instead",
+ )
+
+ return _dispatch_aws_sdk_json(service_info, service_name, action, input_data)
+
+
_SERVICE_DISPATCH = {
"arn:aws:states:::sqs:sendMessage": _invoke_sqs_send_message,
"arn:aws:states:::sns:publish": _invoke_sns_publish,
diff --git a/tests/test_services.py b/tests/test_services.py
index b88b9c8e..567a3147 100644
--- a/tests/test_services.py
+++ b/tests/test_services.py
@@ -4424,6 +4424,155 @@ def test_sfn_intrinsic_nested(sfn, sfn_sync):
assert output["result"] == {"key": "hello"}
+# ===================================================================
+# Step Functions — aws-sdk:* generic dispatcher tests
+# ===================================================================
+
+
+def test_sfn_aws_sdk_secretsmanager_create_and_get(sfn, sfn_sync, sm):
+ """aws-sdk:secretsmanager integration creates and retrieves a secret."""
+ import uuid as _uuid
+
+ secret_name = f"sfn-sdk-test-{_uuid.uuid4().hex[:8]}"
+ sm_name = f"sdk-sm-{_uuid.uuid4().hex[:8]}"
+
+ definition = json.dumps({
+ "StartAt": "CreateSecret",
+ "States": {
+ "CreateSecret": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:secretsmanager:CreateSecret",
+ "Parameters": {
+ "Name": secret_name,
+ "SecretString": "hunter2",
+ },
+ "ResultPath": "$.createResult",
+ "Next": "DescribeSecret",
+ },
+ "DescribeSecret": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:secretsmanager:DescribeSecret",
+ "Parameters": {
+ "SecretId": secret_name,
+ },
+ "ResultPath": "$.describeResult",
+ "Next": "Done",
+ },
+ "Done": {"Type": "Succeed"},
+ },
+ })
+
+ sm_arn = sfn_sync.create_state_machine(
+ name=sm_name,
+ definition=definition,
+ roleArn="arn:aws:iam::000000000000:role/sfn-role",
+ )["stateMachineArn"]
+
+ resp = sfn_sync.start_sync_execution(stateMachineArn=sm_arn, input=json.dumps({}))
+ assert resp["status"] == "SUCCEEDED", f"Execution failed: {resp.get('error')} — {resp.get('cause')}"
+ output = json.loads(resp["output"])
+ assert "createResult" in output
+ assert output["createResult"]["Name"] == secret_name
+ assert "describeResult" in output
+ assert output["describeResult"]["Name"] == secret_name
+
+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+
+
+def test_sfn_aws_sdk_dynamodb_put_and_get(sfn, sfn_sync, ddb):
+ """aws-sdk:dynamodb integration puts and gets an item."""
+ import uuid as _uuid
+
+ table_name = f"sfn-sdk-ddb-{_uuid.uuid4().hex[:8]}"
+ sm_name = f"sdk-ddb-{_uuid.uuid4().hex[:8]}"
+
+ ddb.create_table(
+ TableName=table_name,
+ KeySchema=[{"AttributeName": "pk", "KeyType": "HASH"}],
+ AttributeDefinitions=[{"AttributeName": "pk", "AttributeType": "S"}],
+ BillingMode="PAY_PER_REQUEST",
+ )
+
+ definition = json.dumps({
+ "StartAt": "PutItem",
+ "States": {
+ "PutItem": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:dynamodb:PutItem",
+ "Parameters": {
+ "TableName": table_name,
+ "Item": {
+ "pk": {"S": "key1"},
+ "data": {"S": "hello"},
+ },
+ },
+ "ResultPath": "$.putResult",
+ "Next": "GetItem",
+ },
+ "GetItem": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:dynamodb:GetItem",
+ "Parameters": {
+ "TableName": table_name,
+ "Key": {
+ "pk": {"S": "key1"},
+ },
+ },
+ "ResultPath": "$.getResult",
+ "Next": "Done",
+ },
+ "Done": {"Type": "Succeed"},
+ },
+ })
+
+ sm_arn = sfn_sync.create_state_machine(
+ name=sm_name,
+ definition=definition,
+ roleArn="arn:aws:iam::000000000000:role/sfn-role",
+ )["stateMachineArn"]
+
+ resp = sfn_sync.start_sync_execution(stateMachineArn=sm_arn, input=json.dumps({}))
+ assert resp["status"] == "SUCCEEDED", f"Execution failed: {resp.get('error')} — {resp.get('cause')}"
+ output = json.loads(resp["output"])
+ assert "getResult" in output
+ item = output["getResult"].get("Item", {})
+ assert item.get("pk", {}).get("S") == "key1"
+ assert item.get("data", {}).get("S") == "hello"
+
+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+
+
+def test_sfn_aws_sdk_unknown_service_fails(sfn, sfn_sync):
+ """aws-sdk integration with unsupported service returns clean error."""
+ import uuid as _uuid
+
+ sm_name = f"sdk-unknown-{_uuid.uuid4().hex[:8]}"
+
+ definition = json.dumps({
+ "StartAt": "BadCall",
+ "States": {
+ "BadCall": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:neptune:DescribeDBClusters",
+ "Parameters": {},
+ "End": True,
+ },
+ },
+ })
+
+ sm_arn = sfn_sync.create_state_machine(
+ name=sm_name,
+ definition=definition,
+ roleArn="arn:aws:iam::000000000000:role/sfn-role",
+ )["stateMachineArn"]
+
+ resp = sfn_sync.start_sync_execution(stateMachineArn=sm_arn, input=json.dumps({}))
+ assert resp["status"] == "FAILED"
+ assert "neptune" in resp.get("cause", "").lower() or "neptune" in resp.get("error", "").lower()
+
+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+
+
# ===================================================================
# ECS — comprehensive tests
# ===================================================================