Skip to content

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

fix(lambda,stepfunctions): aws-sdk:lambda dispatch and version readiness (#665)

Jay Janssen71c3bdee10d7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f84892e6..5b409add 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,10 @@ Versioning follows [Semantic Versioning](https://semver.org/).
### Changed
- **Test harness — xdist session-startup reset coordination** — the per-worker `autouse` `reset_server` fixture previously had every xdist worker hit `/_ministack/reset` on session start, so a slower worker's reset could fire after a faster worker had already begun creating fixtures, wiping that state mid-test (most visibly as occasional `list_functions()` empty results in `test_lambda_create_invoke`). The first worker now wins an `O_EXCL` file lock and runs the reset; the others wait briefly for a marker file and skip. Single-process pytest (no xdist) keeps the original behaviour. Removes a class of CI flakes that only reproduced under parallel load.
+### Fixed
+- **Step Functions Lambda AWS SDK integrations** — `arn:aws:states:::aws-sdk:lambda:getAlias` and `getFunctionConfiguration` now dispatch through the Lambda REST emulator, including JSONPath-resolved `FunctionName`, `Name`, and `Qualifier` parameters. This unblocks readiness workflows that verify a Lambda alias and its published version before invoking it.
+- **Lambda published-version readiness** — published version snapshots created while `$LATEST` is still `Pending/InProgress` now transition to `Active/Successful` with the function, so `GetFunctionConfiguration --qualifier <version>` converges instead of staying stuck after the alias points at the version.
+
---
## [1.3.41] — 2026-05-16
diff --git a/ministack/services/eventbridge.py b/ministack/services/eventbridge.py
index 48336e61..50c4653a 100644
--- a/ministack/services/eventbridge.py
+++ b/ministack/services/eventbridge.py
@@ -20,9 +20,9 @@ Supports: CreateEventBus, UpdateEventBus, DeleteEventBus, ListEventBuses, Descri
ListEventSources, PutPartnerEvents.
"""
+import calendar
import copy
import fnmatch
-import calendar
import hashlib
import json
import logging
diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.py
index dffc1322..0c7fab4f 100644
--- a/ministack/services/lambda_svc.py
+++ b/ministack/services/lambda_svc.py
@@ -1741,6 +1741,14 @@ def _schedule_state_transition(func_name: str, delay: float) -> None:
"""Flip State and LastUpdateStatus to the post-ready values after `delay`."""
acct = get_account_id()
+ def _mark_ready(cfg: dict) -> None:
+ cfg["State"] = "Active"
+ cfg["StateReason"] = ""
+ cfg["StateReasonCode"] = ""
+ cfg["LastUpdateStatus"] = "Successful"
+ cfg["LastUpdateStatusReason"] = ""
+ cfg["LastUpdateStatusReasonCode"] = ""
+
def _flip():
time.sleep(delay)
# Re-fetch under the correct account context so multi-tenant cases work.
@@ -1749,13 +1757,14 @@ def _schedule_state_transition(func_name: str, delay: float) -> None:
fn = _functions.get(func_name)
if not fn:
return
- cfg = fn.get("config", {})
- cfg["State"] = "Active"
- cfg["StateReason"] = ""
- cfg["StateReasonCode"] = ""
- cfg["LastUpdateStatus"] = "Successful"
- cfg["LastUpdateStatusReason"] = ""
- cfg["LastUpdateStatusReasonCode"] = ""
+ _mark_ready(fn.get("config", {}))
+ for version in fn.get("versions", {}).values():
+ cfg = version.get("config", {})
+ if (
+ cfg.get("State") == "Pending"
+ or cfg.get("LastUpdateStatus") == "InProgress"
+ ):
+ _mark_ready(cfg)
finally:
_request_account_id.reset(token)
diff --git a/ministack/services/s3.py b/ministack/services/s3.py
index 8562bbbe..05355504 100644
--- a/ministack/services/s3.py
+++ b/ministack/services/s3.py
@@ -892,9 +892,16 @@ def _put_bucket_lifecycle(name: str, body: bytes):
ns = {"s3": "http://s3.amazonaws.com/doc/2006-03-01/"}
for rule_el in root.findall("Rule", ns) or root.findall("s3:Rule", ns):
rule: dict = {}
- _lc_text = lambda el, tag: (el.findtext(tag) or el.findtext(f"s3:{tag}", namespaces=ns) or "")
- _lc_find = lambda el, tag: (el.find(tag) or el.find(f"s3:{tag}", ns))
- _lc_findall = lambda el, tag: (el.findall(tag) or el.findall(f"s3:{tag}", ns))
+
+ def _lc_text(el, tag):
+ return el.findtext(tag) or el.findtext(f"s3:{tag}", namespaces=ns) or ""
+
+ def _lc_find(el, tag):
+ return el.find(tag) or el.find(f"s3:{tag}", ns)
+
+ def _lc_findall(el, tag):
+ return el.findall(tag) or el.findall(f"s3:{tag}", ns)
+
id_val = _lc_text(rule_el, "ID")
if id_val:
rule["ID"] = id_val
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 8fbfd1a4..ef3550a1 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -3055,7 +3055,6 @@ _AWS_SDK_SERVICE_MAP = {
"rdsdata": {"protocol": "rest-json", "service_key": "rds-data"},
# REST-XML services: per-op path templates, header/querystring routing, XML responses
"s3": {"protocol": "rest-xml", "service_key": "s3"},
- # REST services (not yet supported via aws-sdk dispatcher)
"lambda": {"protocol": "rest"},
}
@@ -3691,6 +3690,87 @@ def _dispatch_aws_sdk_rest_json(service_info, service_name, action, input_data):
return _convert_keys_to_sfn_convention(result)
+def _dispatch_aws_sdk_lambda_rest(service_info, service_name, action, input_data):
+ """Dispatch the Lambda REST aws-sdk calls needed by Step Functions workflows."""
+ from urllib.parse import quote
+
+ from ministack import app
+
+ 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",
+ )
+
+ pascal_action = action[0].upper() + action[1:] if action else action
+ input_data = input_data or {}
+ query_params = {}
+
+ if pascal_action == "GetAlias":
+ function_name = input_data.get("FunctionName", "")
+ alias_name = input_data.get("Name", "")
+ path = (
+ "/2015-03-31/functions/"
+ f"{quote(str(function_name), safe=':')}/aliases/{quote(str(alias_name), safe='')}"
+ )
+ elif pascal_action == "GetFunctionConfiguration":
+ function_name = input_data.get("FunctionName", "")
+ path = f"/2015-03-31/functions/{quote(str(function_name), safe=':')}/configuration"
+ qualifier = input_data.get("Qualifier")
+ if qualifier is not None:
+ query_params["Qualifier"] = str(qualifier)
+ else:
+ raise _ExecutionError(
+ "States.Runtime",
+ f"aws-sdk:{service_name}:{action} is not yet implemented in MiniStack "
+ "(lambda REST dispatcher covers getAlias and getFunctionConfiguration)",
+ )
+
+ headers = {
+ "content-type": "application/json",
+ "host": f"{service_key}.{get_region()}.amazonaws.com",
+ "authorization": (
+ f"AWS4-HMAC-SHA256 Credential=test/20260101/{get_region()}/{service_key}/aws4_request"
+ ),
+ }
+
+ coro = handler("GET", path, headers, b"", query_params)
+ try:
+ coro.send(None)
+ except StopIteration as stop:
+ status, resp_headers, resp_body = stop.value
+ else:
+ coro.close()
+ loop = asyncio.new_event_loop()
+ try:
+ status, resp_headers, resp_body = loop.run_until_complete(
+ handler("GET", path, headers, b"", query_params)
+ )
+ finally:
+ loop.close()
+
+ decoded = resp_body.decode("utf-8") if isinstance(resp_body, bytes) else resp_body
+ if status >= 400:
+ try:
+ err_data = json.loads(decoded)
+ code = err_data.get("__type") or err_data.get("code") or "ServiceException"
+ msg = err_data.get("message") or err_data.get("Message") or decoded
+ raise _ExecutionError(_prefix_sdk_error(service_name, code), msg)
+ except _ExecutionError:
+ raise
+ except Exception:
+ raise _ExecutionError(_prefix_sdk_error(service_name, "ServiceException"), decoded)
+
+ try:
+ result = json.loads(decoded) if decoded else {}
+ except (json.JSONDecodeError, TypeError):
+ return decoded
+
+ return _convert_keys_to_sfn_convention(result)
+
+
# ---------------------------------------------------------------------------
# REST-XML aws-sdk dispatch (S3)
# ---------------------------------------------------------------------------
@@ -4044,6 +4124,8 @@ def _invoke_aws_sdk_integration(resource, input_data):
return _dispatch_aws_sdk_rest_json(service_info, service_name, action, input_data)
elif protocol == "rest-xml":
return _dispatch_aws_sdk_rest_xml(service_info, service_name, action, input_data)
+ elif protocol == "rest" and service_name == "lambda":
+ return _dispatch_aws_sdk_lambda_rest(service_info, service_name, action, input_data)
else:
raise _ExecutionError(
"States.Runtime",
diff --git a/tests/test_lambda.py b/tests/test_lambda.py
index 4d484bf6..b67548b8 100644
--- a/tests/test_lambda.py
+++ b/tests/test_lambda.py
@@ -1213,6 +1213,40 @@ def test_lambda_publish_version_snapshot(lam):
assert "1" in version_nums
assert "$LATEST" in version_nums
+
+def test_lambda_published_version_readiness_follows_function(lam):
+ """Published versions created during function bootstrap become Active."""
+ fn = f"qa-lam-version-ready-{_uuid_mod.uuid4().hex[:8]}"
+ lam.create_function(
+ FunctionName=fn,
+ Runtime="python3.12",
+ Role="arn:aws:iam::000000000000:role/r",
+ Handler="index.handler",
+ Code={"ZipFile": _zip_lambda("def handler(e,c): return 'v1'")},
+ Publish=True,
+ )
+
+ deadline = time.time() + 3
+ latest = version = None
+ while time.time() < deadline:
+ latest = lam.get_function_configuration(FunctionName=fn)
+ version = lam.get_function_configuration(FunctionName=fn, Qualifier="1")
+ if (
+ latest["State"] == "Active"
+ and latest["LastUpdateStatus"] == "Successful"
+ and version["State"] == "Active"
+ and version["LastUpdateStatus"] == "Successful"
+ ):
+ break
+ time.sleep(0.1)
+
+ assert latest["State"] == "Active"
+ assert latest["LastUpdateStatus"] == "Successful"
+ assert version["Version"] == "1"
+ assert version["State"] == "Active"
+ assert version["LastUpdateStatus"] == "Successful"
+
+
def test_lambda_function_concurrency(lam):
"""PutFunctionConcurrency / GetFunctionConcurrency / DeleteFunctionConcurrency."""
code = _zip_lambda("def handler(e,c): return {}")
@@ -3675,8 +3709,8 @@ def test_nodejs_worker_aws_sdk_v3_stub_wire_roundtrip(lam, ssm):
router.py undetected by the resolution-only tests).
"""
import shutil
-
import uuid as _uuid
+
if not shutil.which("node"):
pytest.skip("node not found on PATH")
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index 0f860b44..d2ce6827 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -741,6 +741,69 @@ def test_sfn_aws_sdk_unknown_service_fails(sfn, sfn_sync):
sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+def test_sfn_aws_sdk_lambda_get_alias_and_configuration(sfn_sync, lam):
+ """aws-sdk:lambda getAlias/getFunctionConfiguration supports JSONPath params."""
+ suffix = _uuid_mod.uuid4().hex[:8]
+ fn = f"sfn-sdk-lambda-{suffix}"
+ sm_name = f"sfn-sdk-lambda-{suffix}"
+
+ lam.create_function(
+ FunctionName=fn,
+ Runtime="python3.12",
+ Role=_LAMBDA_ROLE,
+ Handler="index.handler",
+ Code={"ZipFile": _make_zip("def handler(e, c): return {'ok': True}")},
+ )
+ version = lam.publish_version(FunctionName=fn)["Version"]
+ lam.create_alias(FunctionName=fn, Name="live", FunctionVersion=version)
+
+ function_arn = f"arn:aws:lambda:us-east-1:000000000000:function:{fn}"
+ definition = json.dumps({
+ "StartAt": "ReadAlias",
+ "States": {
+ "ReadAlias": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:lambda:getAlias",
+ "Parameters": {
+ "FunctionName.$": "$.functionName",
+ "Name.$": "$.aliasName",
+ },
+ "ResultPath": "$.alias",
+ "Next": "ReadConfig",
+ },
+ "ReadConfig": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::aws-sdk:lambda:getFunctionConfiguration",
+ "Parameters": {
+ "FunctionName.$": "$.functionName",
+ "Qualifier.$": "$.alias.FunctionVersion",
+ },
+ "ResultPath": "$.config",
+ "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({"functionName": function_arn, "aliasName": "live"}),
+ )
+ assert resp["status"] == "SUCCEEDED", f"Execution failed: {resp.get('error')} — {resp.get('cause')}"
+ output = json.loads(resp["output"])
+ assert output["alias"]["Name"] == "live"
+ assert output["alias"]["FunctionVersion"] == version
+ assert output["config"]["FunctionName"] == fn
+ assert output["config"]["Version"] == version
+
+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+
+
def test_sfn_optimized_start_execution_returns_execution_arn(sfn, sfn_sync):
"""Optimized states:startExecution returns the child ExecutionArn."""
suffix = _uuid_mod.uuid4().hex[:8]
@@ -4326,4 +4389,3 @@ def test_sfn_jsonata_assign_reuses_input(sfn_sync):
assert json.loads(resp["output"]) == "hello world"
finally:
sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
-