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
release v1.3.40 (#654)
Nahuel Nucera2caacfffbf0a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9e6368d4..306535a9 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -7,6 +7,20 @@ Versioning follows [Semantic Versioning](https://semver.org/).---+## [1.3.40] — 2026-05-15++### Added+- **Cognito invitation and verification emails via SES** — `AdminCreateUser`, `SignUp`, `ResendConfirmationCode`, `ForgotPassword`, and `AdminResetUserPassword` now hand their welcome / temporary-password / verification mail to the in-process SES emulator, so simulated apps see the message in `/_ministack/ses/messages` and it relays via SMTP when `SMTP_HOST` is set. Mirrors AWS behaviour: `MessageAction=SUPPRESS` skips, `RESEND` re-sends, `DesiredDeliveryMediums=["SMS"]` excludes email, and template placeholders (`{username}`, `{####}`) expand. Sender resolves to `EmailConfiguration.From`, falling back to `[email protected]` (overridable via `COGNITO_DEFAULT_FROM`); set `COGNITO_EMAIL_ENABLED=false` to short-circuit globally. Adds the previously-missing `ResendConfirmationCode` action while wiring the delivery path. Contributed by @kjdev.+- **Step Functions JSONata `Assign` + workflow variables** — state-level `Assign` fields now bind values into an execution-scoped variable store, and later JSONata expressions can reference them as `$name` (with dotted-path access like `$user.email`). Pass `$states.result` resolves to the computed Output; Task `$states.result` to the raw API result; Catch handlers expose `$states.errorOutput`. Undefined references surface as `States.QueryEvaluationError`, matching the AWS error code for JSONata evaluation failures. Reported by @youngkwangk.++### Fixed+- **Cognito alias-attribute user lookup** — `_resolve_user` now honors the pool's `AliasAttributes` and `UsernameAttributes`, so signing in by `email` / `phone_number` / `preferred_username` resolves correctly. Email and phone aliases require the corresponding `_verified` attribute to equal `"true"` (matches AWS); `preferred_username` has no verification gate. The change routes `AdminInitiateAuth`, `InitiateAuth`, `AdminRespondToAuthChallenge`, `RespondToAuthChallenge`, `ConfirmSignUp`, `ForgotPassword`, `ConfirmForgotPassword`, and the hosted-UI `/login` form through the resolver — internal call sites that need the canonical username (group iteration, create-time uniqueness, post-code token issuance) are left untouched. Contributed by @rjmackay.+- **SQS `ReceiveMessage` `InternalError` on FIFO queues with `RedrivePolicy`** — a double-JSON-encoded `RedrivePolicy` value slipped past `CreateQueue` / `SetQueueAttributes`, then crashed `_dlq_sweep` on receive because `json.loads` returned a string (not a dict) and `.get()` raised `AttributeError`. MiniStack now validates `RedrivePolicy` at intake (parseable JSON object with non-empty `deadLetterTargetArn` and numeric `maxReceiveCount` between 1 and 1000) and rejects malformed values with `InvalidAttributeValue` (400), matching real AWS. Receive carries a defensive guard so legacy persisted state doesn't crash. Reported by @rbonestell.+- **DynamoDB `if_not_exists` arithmetic in `SET` expressions** — `SET v = (if_not_exists(v, :d) - :amt)` previously dropped the arithmetic and assigned the resolved value directly: the outer parens kept every token at depth > 0, so the top-level operator scan never saw the `-` at depth 0. `_eval_set_value` now strips a single layer of matched outer parens before parsing, guarded so `(a) + (b)` (two adjacent groups) isn't accidentally flattened. Reported by @youngkwangk.+- **S3 → Lambda notifications fire for non-boto3 SDK clients** — MiniStack's notification XML parser only recognised the legacy `<CloudFunction>` ARN tag, which is what botocore wire-serialises `LambdaFunctionArn` as. AWS SDK for Java v2, Go SDK, Terraform's `aws_s3_bucket_notification`, and any hand-crafted XML send the modern `<LambdaFunctionArn>` tag — MiniStack silently dropped those configs, so uploads succeeded but the Lambda never fired. Both shapes are now accepted, matching real S3. Reported by @michael-denyer.++---+## [1.3.39] — 2026-05-15### Addeddiff --git a/ministack/services/batch.py b/ministack/services/batch.pyindex 5e9cb813..107c3400 100644--- a/ministack/services/batch.py+++ b/ministack/services/batch.py@@ -10,7 +10,6 @@ here, not a real container runner.import copyimport jsonimport logging-import osimport timefrom ministack.core.responses import (@@ -185,123 +184,11 @@ def _describe_job_definitions(p):return _json(200, {"jobDefinitions": revs})-def _detect_host_limits():- """Return the host's installed CPU/memory ceiling MS can compare against.-- Reports *installed* capacity, not currently-available — the gate's purpose- is "could this jobdef ever run on this host", which is a stable property,- not a fluctuating one. A dimension that can't be confidently measured on- this platform returns ``None`` and the corresponding check is skipped, so- we don't false-positive on exotic environments.- """- vcpu = None- try:- vcpu = os.cpu_count()- except Exception:- vcpu = None-- memory_mib = None- try:- page = os.sysconf("SC_PAGE_SIZE")- pages = os.sysconf("SC_PHYS_PAGES")- if isinstance(page, int) and isinstance(pages, int) and page > 0 and pages > 0:- memory_mib = (page * pages) // (1024 * 1024)- except (AttributeError, ValueError, OSError):- memory_mib = None- return {"vcpu": vcpu, "memory_mib": memory_mib}---def _parse_resource_requirements(container_props):- """Pull VCPU + MEMORY out of a jobdef's ``containerProperties.resourceRequirements``.- Returns ``(vcpu_or_None, memory_mib_or_None)``. Malformed entries are- treated as absent so we never block on parser quirks.- """- reqs = (container_props or {}).get("resourceRequirements") or []- vcpu = None- memory_mib = None- for r in reqs:- if not isinstance(r, dict):- continue- kind = (r.get("type") or "").upper()- raw = r.get("value")- if raw is None:- continue- try:- num = float(raw)- except (TypeError, ValueError):- continue- if kind == "VCPU":- vcpu = num- elif kind == "MEMORY":- try:- memory_mib = int(num)- except (TypeError, ValueError):- continue- return vcpu, memory_mib---def _resolve_jobdef(ref):- """Look up a jobdef record by ``name``, ``name:revision``, or full ARN.- Returns the record or ``None`` — never raises so callers can fall through.- """- if not ref:- return None- short = ref.split("/")[-1]- if ":" in short:- name, _, rev = short.rpartition(":")- try:- target_rev = int(rev)- except ValueError:- return None- for r in _job_definitions.get(name, []):- if r.get("revision") == target_rev:- return r- return None- revs = _job_definitions.get(short, [])- return revs[-1] if revs else None---def _check_host_fit(container_props):- """Return an error message if the jobdef can't physically run on this host,- else ``None``. Both dimensions must be measurable on both sides for the- check to fire — anything ambiguous passes through.- """- limits = _detect_host_limits()- req_vcpu, req_mem = _parse_resource_requirements(container_props)-- over = []- if req_vcpu is not None and limits["vcpu"] is not None and req_vcpu > limits["vcpu"]:- over.append(f"VCPU={req_vcpu:g} (host has {limits['vcpu']})")- if req_mem is not None and limits["memory_mib"] is not None and req_mem > limits["memory_mib"]:- over.append(f"MEMORY={req_mem} MiB (host has {limits['memory_mib']} MiB)")- if not over:- return None- return (- "SubmitJob refused: jobdef requests "- + ", ".join(over)- + ". Reduce resourceRequirements for local testing, "- "or run this jobdef against real AWS Batch."- )--# ─── jobs ───────────────────────────────────────────────────────def _submit_job(p):name = p.get("jobName")if not name:return error_response_json("ClientException", "jobName is required", 400)-- # Honest fail-fast for the local-emulator case where the jobdef can't- # physically fit on this host. Real AWS Batch has unlimited compute so- # this failure mode doesn't exist there; in MS we'd otherwise return- # SUCCEEDED for a job that could never actually run, hiding the problem- # behind a second describe_jobs call. Issue #650.- jobdef = _resolve_jobdef(p.get("jobDefinition"))- if jobdef is not None:- fit_err = _check_host_fit(jobdef.get("containerProperties"))- if fit_err is not None:- logger.warning("Batch SubmitJob refused (%s): %s", name, fit_err)- return error_response_json("ClientException", fit_err, 400)-job_id = new_uuid()now = _now_ms()rec = {diff --git a/pyproject.toml b/pyproject.tomlindex d737d358..f411c29d 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"[project]name = "ministack"-version = "1.3.39"+version = "1.3.40"description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"readme = "README.md"license = { file = "LICENSE" }diff --git a/tests/test_batch.py b/tests/test_batch.pyindex fbb3781a..efe8392d 100644--- a/tests/test_batch.py+++ b/tests/test_batch.py@@ -98,156 +98,3 @@ def test_batch_account_isolation():b_qs = [q["jobQueueName"] for q in b.describe_job_queues()["jobQueues"]]assert name in a_qsassert name not in b_qs---# ----------------------------------------------------------------------------# SubmitJob host-resource gate (issue #650)-# -----------------------------------------------------------------------------def _register(batch, name, reqs=None):- container = {"image": "alpine:3.20", "command": ["echo", "hi"]}- if reqs is not None:- container["resourceRequirements"] = reqs- return batch.register_job_definition(- jobDefinitionName=name, type="container", containerProperties=container,- )---def test_batch_submit_job_refused_when_jobdef_exceeds_host(batch):- """Issue #650: jobdef requesting more resources than MS' host can provide- must surface at the SubmitJob call (400 ClientException) — not silently- return SUCCEEDED for a job that could never run.- """- from botocore.exceptions import ClientError- name = f"oversize-{_uid()}"- _register(batch, name, reqs=[- {"type": "VCPU", "value": "256"}, # impossibly high- {"type": "MEMORY", "value": "9999999"},- ])- with pytest.raises(ClientError) as exc:- batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=f"{name}:1")- err = exc.value.response["Error"]- assert err["Code"] == "ClientException"- msg = err["Message"]- assert "SubmitJob refused" in msg- assert "VCPU=256" in msg- assert "MEMORY=9999999" in msg---def test_batch_submit_job_vcpu_only_over_fails(batch):- """When only VCPU exceeds, the message reports only VCPU."""- from botocore.exceptions import ClientError- name = f"vcpu-{_uid()}"- _register(batch, name, reqs=[- {"type": "VCPU", "value": "256"},- {"type": "MEMORY", "value": "64"},- ])- with pytest.raises(ClientError) as exc:- batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=f"{name}:1")- msg = exc.value.response["Error"]["Message"]- assert "VCPU=256" in msg- assert "MEMORY" not in msg # only the over-capacity dimension surfaces---def test_batch_submit_job_memory_only_over_fails(batch):- from botocore.exceptions import ClientError- name = f"mem-{_uid()}"- _register(batch, name, reqs=[- {"type": "VCPU", "value": "1"},- {"type": "MEMORY", "value": "9999999"},- ])- with pytest.raises(ClientError) as exc:- batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=f"{name}:1")- msg = exc.value.response["Error"]["Message"]- assert "MEMORY=9999999" in msg- assert "VCPU" not in msg---def test_batch_submit_job_fitting_resources_succeeds(batch):- """Regression: a jobdef well within the host's ceiling must still pass- through to the stub-SUCCEEDED behavior MS has always had.- """- name = f"fit-{_uid()}"- _register(batch, name, reqs=[- {"type": "VCPU", "value": "1"},- {"type": "MEMORY", "value": "128"},- ])- resp = batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=f"{name}:1")- assert "jobId" in resp- desc = batch.describe_jobs(jobs=[resp["jobId"]])["jobs"][0]- assert desc["status"] == "SUCCEEDED"---def test_batch_submit_job_no_resource_requirements_succeeds(batch):- """A jobdef without `resourceRequirements` has nothing to compare against;- pass through unchanged.- """- name = f"noreqs-{_uid()}"- _register(batch, name, reqs=None)- resp = batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=f"{name}:1")- assert "jobId" in resp---def test_batch_submit_job_unknown_jobdef_passes_through(batch):- """When the `jobDefinition` reference can't be resolved, MS preserves its- existing permissive behavior (don't introduce a *new* failure mode while- fixing a different one).- """- resp = batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition="does-not-exist:99")- assert "jobId" in resp---def test_batch_submit_job_resolves_by_name_takes_latest_revision(batch):- """`jobDefinition='name'` (no `:rev`) resolves to the latest revision."""- name = f"byname-{_uid()}"- _register(batch, name, reqs=[{"type": "VCPU", "value": "1"},- {"type": "MEMORY", "value": "128"}])- # Bump revision; the latest one is still small, gate must still pass.- _register(batch, name, reqs=[{"type": "VCPU", "value": "1"},- {"type": "MEMORY", "value": "64"}])- resp = batch.submit_job(jobName=f"r-{_uid()}", jobQueue="q",- jobDefinition=name) # no :rev- assert "jobId" in resp---def test_batch_resource_check_skipped_when_host_unmeasurable(monkeypatch):- """If host detection returns None for every dimension (exotic platform),- the gate must skip silently — no false-positive refusals.- """- from ministack.services import batch as batch_mod- monkeypatch.setattr(- batch_mod, "_detect_host_limits",- lambda: {"vcpu": None, "memory_mib": None},- )- container = {- "image": "alpine:3.20",- "command": ["echo", "hi"],- "resourceRequirements": [- {"type": "VCPU", "value": "9999"},- {"type": "MEMORY", "value": "9999999"},- ],- }- assert batch_mod._check_host_fit(container) is None---def test_batch_resource_check_skipped_when_jobdef_dimension_unmeasurable(monkeypatch):- """If the jobdef declares one dimension but not the other, only the- declared one is compared — no spurious failures from absent fields.- """- from ministack.services import batch as batch_mod- monkeypatch.setattr(- batch_mod, "_detect_host_limits",- lambda: {"vcpu": 2, "memory_mib": 1024},- )- container = {- "image": "alpine:3.20",- "command": ["echo", "hi"],- "resourceRequirements": [{"type": "VCPU", "value": "1"}], # only VCPU- }- assert batch_mod._check_host_fit(container) is None