Skip to content

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

fix(lambda): share reserved concurrency across versions (#1829)

Johannes Grumböckf7c8e12adf6c
diff --git a/ministack/services/lambda_svc.py b/ministack/services/lambda_svc.py
index 87a35fe7..973ed479 100644
--- a/ministack/services/lambda_svc.py
+++ b/ministack/services/lambda_svc.py
@@ -4856,7 +4856,9 @@ def _inflight_key(config: dict) -> str:
account, region = _account_region_from_function_config(config)
except Exception:
account, region = get_account_id(), get_region()
- return f"{account}:{region}:{config.get('FunctionName', '?')}:{config.get('Version', '$LATEST')}"
+ # Reserved concurrency belongs to the function, not an individual
+ # published version or alias. All versions therefore share one counter.
+ return f"{account}:{region}:{config.get('FunctionName', '?')}"
def _reserved_concurrency(func: dict, config: dict) -> int | None:
diff --git a/tests/test_lambda.py b/tests/test_lambda.py
index 7d70ef9f..c95e9e91 100644
--- a/tests/test_lambda.py
+++ b/tests/test_lambda.py
@@ -6684,6 +6684,30 @@ def test_execution_slot_zero_reserved_throttles():
assert limit == "function"
+def test_execution_slot_reserved_concurrency_shared_across_versions():
+ """A published version and $LATEST share the function's reserved limit."""
+ name = f"cap-version-{_uuid_mod.uuid4().hex[:8]}"
+ func = {"concurrency": 1}
+ latest_config = {
+ "FunctionName": name,
+ "Version": "$LATEST",
+ "FunctionArn": f"arn:aws:lambda:us-east-1:000000000000:function:{name}",
+ }
+ published_config = {**latest_config, "Version": "1"}
+
+ latest_slot, limit = lsvc._acquire_execution_slot(func, latest_config)
+ assert latest_slot is not None
+ assert limit is None
+ try:
+ published_slot, limit = lsvc._acquire_execution_slot(func, published_config)
+ if published_slot is not None:
+ lsvc._release_execution_slot(published_slot)
+ assert published_slot is None
+ assert limit == "function"
+ finally:
+ lsvc._release_execution_slot(latest_slot)
+
+
def test_account_concurrency_cap_rejects(monkeypatch):
"""Global account cap: 3 in-use total → 4th is throttled as acct_cap."""
monkeypatch.setattr(lsvc, "_ACCOUNT_CONCURRENCY_CAP", 3)