Skip to content

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

fix:improve Persist state across all services (#144)

Nahuel Nucera49caba61ffd3
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 07cca5b4..44972892 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,12 +7,27 @@ Versioning follows [Semantic Versioning](https://semver.org/).
---
+## [1.1.40] — 2026-04-06
+
+### Added
+- **State persistence for ALL services** — 11 remaining services now support `PERSIST_STATE=1`: ALB, Glue, EFS, WAF, Athena, EMR, CloudFront, ACM, Firehose, SES, SES v2. All 35+ services now persist state across restarts.
+- **Step Functions persistence** — state machines, executions, tags, and activities persist. RUNNING executions restored as FAILED with `States.ServiceRestart`. Contributed by @TheJokersThief (#141)
+- **IAM `ListEntitiesForPolicy`** — returns users, roles, and groups attached to a managed policy. Supports `EntityFilter` and `PathPrefix`. Contributed by @TheJokersThief (#143)
+
+### Tests
+- 5 cross-service integration tests: S3→SQS events, SNS→SQS fanout, DynamoDB streams→Lambda, SQS ESM→Lambda, CloudFormation full stack (S3+Lambda+DynamoDB). Contributed by @DaviReisVieira (#142)
+
+---
+
## [1.1.39] — 2026-04-06
### Fixed
- **AppSync persistence crash on restart** — `restore_state()` called before it was defined in the file, causing `NameError` when `PERSIST_STATE=1` and restarting. Reported by @samiuoi (#66)
- **Cognito `AdminSetUserPassword` with `Permanent=false`** — now correctly sets `UserStatus` to `FORCE_CHANGE_PASSWORD`. Previously the password was updated but the status wasn't changed.
+### Community
+- **README: Community Integrations section** — [StackPort](https://github.com/DaviReisVieira/stackport) visual dashboard by @DaviReisVieira, [Aspire Hosting](https://github.com/McDoit/aspire-hosting-ministack) .NET integration by @McDoit
+
### Tests
- 10 new tests: KMS (list policies, rotation period), ElastiCache (parameter groups, snapshots, tags), Lambda (Image CRUD, update ImageUri, provided runtime), SecretsManager (rotate secret), Firehose (S3 destination writes)
- 1011 tests total
diff --git a/ministack/app.py b/ministack/app.py
index 71b971cc..f346fcce 100644
--- a/ministack/app.py
+++ b/ministack/app.py
@@ -591,6 +591,17 @@ async def _handle_lifespan(scope, receive, send):
"elasticache": elasticache.get_state,
"appsync": appsync.get_state,
"stepfunctions": stepfunctions.get_state,
+ "alb": alb.get_state,
+ "glue": glue.get_state,
+ "efs": efs.get_state,
+ "waf": waf.get_state,
+ "athena": athena.get_state,
+ "emr": emr.get_state,
+ "cloudfront": cloudfront.get_state,
+ "acm": acm.get_state,
+ "firehose": firehose.get_state,
+ "ses": ses.get_state,
+ "ses_v2": ses_v2.get_state,
})
await send({"type": "lifespan.shutdown.complete"})
return
diff --git a/ministack/services/acm.py b/ministack/services/acm.py
index 1ff1dc73..71a7fbed 100644
--- a/ministack/services/acm.py
+++ b/ministack/services/acm.py
@@ -7,11 +7,14 @@ Supports: RequestCertificate, DescribeCertificate, ListCertificates,
UpdateCertificateOptions, RenewCertificate, ResendValidationEmail.
"""
+import copy
import json
import os
import logging
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
+
from ministack.core.responses import error_response_json, json_response, new_uuid, now_iso
logger = logging.getLogger("acm")
@@ -22,6 +25,19 @@ REGION = os.environ.get("MINISTACK_REGION", "us-east-1")
_certificates: dict = {} # arn -> certificate dict
+def get_state():
+ return copy.deepcopy({"_certificates": _certificates})
+
+
+def restore_state(data):
+ _certificates.update(data.get("_certificates", {}))
+
+
+_restored = load_state("acm")
+if _restored:
+ restore_state(_restored)
+
+
def _future_iso(seconds):
return time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(time.time() + seconds))
diff --git a/ministack/services/alb.py b/ministack/services/alb.py
index b5a68074..5ceb20da 100644
--- a/ministack/services/alb.py
+++ b/ministack/services/alb.py
@@ -16,6 +16,7 @@ Supports:
"""
import base64
+import copy
import fnmatch
import json
import logging
@@ -25,6 +26,7 @@ import string
import time
from urllib.parse import parse_qs
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import new_uuid
logger = logging.getLogger("alb")
@@ -45,6 +47,35 @@ _tags: dict = {} # res_arn -> [{Key, Value}]
_lb_attrs: dict = {} # lb_arn -> [{Key, Value}]
_tg_attrs: dict = {} # tg_arn -> [{Key, Value}]
+
+def get_state():
+ return copy.deepcopy({
+ "_lbs": _lbs,
+ "_tgs": _tgs,
+ "_listeners": _listeners,
+ "_rules": _rules,
+ "_targets": _targets,
+ "_tags": _tags,
+ "_lb_attrs": _lb_attrs,
+ "_tg_attrs": _tg_attrs,
+ })
+
+
+def restore_state(data):
+ _lbs.update(data.get("_lbs", {}))
+ _tgs.update(data.get("_tgs", {}))
+ _listeners.update(data.get("_listeners", {}))
+ _rules.update(data.get("_rules", {}))
+ _targets.update(data.get("_targets", {}))
+ _tags.update(data.get("_tags", {}))
+ _lb_attrs.update(data.get("_lb_attrs", {}))
+ _tg_attrs.update(data.get("_tg_attrs", {}))
+
+
+_restored = load_state("alb")
+if _restored:
+ restore_state(_restored)
+
# ---------------------------------------------------------------------------
# Small helpers
# ---------------------------------------------------------------------------
diff --git a/ministack/services/athena.py b/ministack/services/athena.py
index fdbcda69..17683809 100644
--- a/ministack/services/athena.py
+++ b/ministack/services/athena.py
@@ -13,6 +13,7 @@ Supports: StartQueryExecution, GetQueryExecution, GetQueryResults,
TagResource, UntagResource, ListTagsForResource.
"""
+import copy
import json
import logging
import os
@@ -20,6 +21,7 @@ import re
import threading
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import error_response_json, json_response, new_uuid
logger = logging.getLogger("athena")
@@ -64,6 +66,38 @@ _data_catalogs: dict = {
_prepared_statements: dict = {} # "workgroup/name" -> statement dict
_tags: dict = {} # arn -> {key: value, ...}
+
+def get_state():
+ return copy.deepcopy(
+ {
+ "_executions": _executions,
+ "_workgroups": _workgroups,
+ "_named_queries": _named_queries,
+ "_data_catalogs": _data_catalogs,
+ "_prepared_statements": _prepared_statements,
+ "_tags": _tags,
+ }
+ )
+
+
+def restore_state(data):
+ global _workgroups, _data_catalogs
+ _executions.clear()
+ _executions.update(data.get("_executions", {}))
+ _workgroups = data.get("_workgroups", _workgroups)
+ _named_queries.clear()
+ _named_queries.update(data.get("_named_queries", {}))
+ _data_catalogs = data.get("_data_catalogs", _data_catalogs)
+ _prepared_statements.clear()
+ _prepared_statements.update(data.get("_prepared_statements", {}))
+ _tags.clear()
+ _tags.update(data.get("_tags", {}))
+
+
+_restored = load_state("athena")
+if _restored:
+ restore_state(_restored)
+
try:
import duckdb
diff --git a/ministack/services/cloudfront.py b/ministack/services/cloudfront.py
index 3f8c1929..492f7728 100644
--- a/ministack/services/cloudfront.py
+++ b/ministack/services/cloudfront.py
@@ -9,6 +9,7 @@ Supports:
Invalidations: CreateInvalidation, ListInvalidations, GetInvalidation
"""
+import copy
import logging
import os
import random
@@ -18,6 +19,7 @@ from datetime import datetime, timezone
from defusedxml.ElementTree import fromstring
from xml.etree.ElementTree import Element, SubElement, tostring
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import new_uuid
logger = logging.getLogger("cloudfront")
@@ -46,6 +48,23 @@ def reset():
_invalidations.clear()
+def get_state():
+ return copy.deepcopy({
+ "distributions": _distributions,
+ "invalidations": _invalidations,
+ })
+
+
+def restore_state(data):
+ _distributions.update(data.get("distributions", {}))
+ _invalidations.update(data.get("invalidations", {}))
+
+
+_restored = load_state("cloudfront")
+if _restored:
+ restore_state(_restored)
+
+
# ---------------------------------------------------------------------------
# ID generators — real CloudFront uses 14-char uppercase alphanumeric IDs
# ---------------------------------------------------------------------------
diff --git a/ministack/services/efs.py b/ministack/services/efs.py
index 448e4744..bfadce08 100644
--- a/ministack/services/efs.py
+++ b/ministack/services/efs.py
@@ -15,6 +15,7 @@ Supports:
Account: DescribeAccountPreferences, PutAccountPreferences
"""
+import copy
import json
import logging
import os
@@ -23,6 +24,8 @@ import re
import string
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
+
logger = logging.getLogger("efs")
ACCOUNT_ID = os.environ.get("MINISTACK_ACCOUNT_ID", "000000000000")
@@ -334,6 +337,35 @@ def _find_resource(resource_id):
_lifecycle_configs: dict = {}
_backup_policies: dict = {}
+
+def get_state():
+ return copy.deepcopy({
+ "file_systems": _file_systems,
+ "mount_targets": _mount_targets,
+ "access_points": _access_points,
+ "lifecycle_configs": _lifecycle_configs,
+ "backup_policies": _backup_policies,
+ })
+
+
+def restore_state(data):
+ _file_systems.clear()
+ _file_systems.update(data.get("file_systems", {}))
+ _mount_targets.clear()
+ _mount_targets.update(data.get("mount_targets", {}))
+ _access_points.clear()
+ _access_points.update(data.get("access_points", {}))
+ _lifecycle_configs.clear()
+ _lifecycle_configs.update(data.get("lifecycle_configs", {}))
+ _backup_policies.clear()
+ _backup_policies.update(data.get("backup_policies", {}))
+
+
+_restored = load_state("efs")
+if _restored:
+ restore_state(_restored)
+
+
def _put_lifecycle_configuration(fs_id, body):
fs = _file_systems.get(fs_id)
if not fs:
diff --git a/ministack/services/emr.py b/ministack/services/emr.py
index bed3b03b..d226b6ae 100644
--- a/ministack/services/emr.py
+++ b/ministack/services/emr.py
@@ -14,6 +14,7 @@ Supports:
Block Public Access: GetBlockPublicAccessConfiguration, PutBlockPublicAccessConfiguration
"""
+import copy
import json
import logging
import os
@@ -21,6 +22,7 @@ import random
import string
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import error_response_json, json_response, new_uuid
logger = logging.getLogger("emr")
@@ -39,6 +41,25 @@ _block_public_access: dict = {
"PermittedPublicSecurityGroupRuleRanges": [],
}
+
+def get_state():
+ return copy.deepcopy({
+ "_clusters": _clusters,
+ "_steps": _steps,
+ "_block_public_access": _block_public_access,
+ })
+
+
+def restore_state(data):
+ _clusters.update(data.get("_clusters", {}))
+ _steps.update(data.get("_steps", {}))
+ _block_public_access.update(data.get("_block_public_access", {}))
+
+
+_restored = load_state("emr")
+if _restored:
+ restore_state(_restored)
+
# ---------------------------------------------------------------------------
# ID generators
# ---------------------------------------------------------------------------
diff --git a/ministack/services/firehose.py b/ministack/services/firehose.py
index 3a4564eb..f3f53936 100644
--- a/ministack/services/firehose.py
+++ b/ministack/services/firehose.py
@@ -15,6 +15,7 @@ in-memory (accessible for testing via PutRecord/PutRecordBatch round-trip).
"""
import asyncio
+import copy
import os
import base64
import json
@@ -22,6 +23,7 @@ import logging
import threading
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import (
error_response_json,
json_response,
@@ -48,6 +50,21 @@ def reset():
_dest_counter = 0
+def get_state() -> dict:
+ return copy.deepcopy({"_streams": _streams, "_dest_counter": _dest_counter})
+
+
+def restore_state(data: dict):
+ global _streams, _dest_counter
+ _streams.update(data.get("_streams", {}))
+ _dest_counter = data.get("_dest_counter", _dest_counter)
+
+
+_restored = load_state("firehose")
+if _restored:
+ restore_state(_restored)
+
+
# ─── helpers ─────────────────────────────────────────────────────────────────
def _stream_arn(name: str) -> str:
diff --git a/ministack/services/glue.py b/ministack/services/glue.py
index 667b6c8a..c5e4c2ad 100644
--- a/ministack/services/glue.py
+++ b/ministack/services/glue.py
@@ -8,6 +8,7 @@ Job execution runs Python scripts via subprocess in background threads.
Crawlers transition through RUNNING state with a configurable timer.
"""
+import copy
import fnmatch
import json
import logging
@@ -17,6 +18,7 @@ import tempfile
import threading
import time
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import error_response_json, json_response, new_uuid
logger = logging.getLogger("glue")
@@ -41,6 +43,38 @@ _triggers: dict = {} # trigger_name -> trigger dict
_workflows: dict = {} # workflow_name -> workflow dict
_workflow_runs: dict = {} # workflow_name -> [run, ...]
+_ALL_STATE = {
+ "databases": _databases,
+ "tables": _tables,
+ "partitions": _partitions,
+ "partition_indexes": _partition_indexes,
+ "connections": _connections,
+ "crawlers": _crawlers,
+ "jobs": _jobs,
+ "job_runs": _job_runs,
+ "tags": _tags,
+ "security_configs": _security_configs,
+ "classifiers": _classifiers,
+ "triggers": _triggers,
+ "workflows": _workflows,
+ "workflow_runs": _workflow_runs,
+}
+
+
+def get_state():
+ return copy.deepcopy(_ALL_STATE)
+
+
+def restore_state(data):
+ for key, store in _ALL_STATE.items():
+ store.clear()
+ store.update(data.get(key, {}))
+
+
+_restored = load_state("glue")
+if _restored:
+ restore_state(_restored)
+
def _arn(resource_type, name):
return f"arn:aws:glue:{REGION}:{ACCOUNT_ID}:{resource_type}/{name}"
diff --git a/ministack/services/ses.py b/ministack/services/ses.py
index 45b78272..64e7ca00 100644
--- a/ministack/services/ses.py
+++ b/ministack/services/ses.py
@@ -23,6 +23,7 @@ Send statistics aggregated into 15-minute buckets per AWS spec.
"""
import base64
+import copy
import hashlib
import json
import logging
@@ -37,6 +38,7 @@ from email.mime.text import MIMEText
from email.policy import default as default_policy
from urllib.parse import parse_qs, unquote
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import new_uuid
logger = logging.getLogger("ses")
@@ -50,6 +52,29 @@ _templates: dict = {}
_configuration_sets: dict = {}
+# ---------------------------------------------------------------------------
+# Persistence helpers
+# ---------------------------------------------------------------------------
+
+def get_state() -> dict:
+ return copy.deepcopy({
+ "_identities": _identities,
+ "_templates": _templates,
+ "_configuration_sets": _configuration_sets,
+ })
+
+
+def restore_state(data: dict):
+ _identities.update(data.get("_identities", {}))
+ _templates.update(data.get("_templates", {}))
+ _configuration_sets.update(data.get("_configuration_sets", {}))
+
+
+_restored = load_state("ses")
+if _restored:
+ restore_state(_restored)
+
+
# ---------------------------------------------------------------------------
# Entry point
# ---------------------------------------------------------------------------
diff --git a/ministack/services/ses_v2.py b/ministack/services/ses_v2.py
index 1ea53bc3..99e94dac 100644
--- a/ministack/services/ses_v2.py
+++ b/ministack/services/ses_v2.py
@@ -8,11 +8,13 @@ Supports: SendEmail, CreateEmailIdentity, GetEmailIdentity, DeleteEmailIdentity,
TagResource, UntagResource, ListTagsForResource.
"""
+import copy
import json
import logging
import os
import re
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import json_response, new_uuid, now_iso
from ministack.services.ses import _build_mime_message, _smtp_relay
@@ -26,6 +28,25 @@ _config_sets: dict = {} # name -> dict
_ses_tags: dict = {} # resource_arn -> [tags]
+def get_state() -> dict:
+ return copy.deepcopy({
+ "_identities": _identities,
+ "_config_sets": _config_sets,
+ "_ses_tags": _ses_tags,
+ })
+
+
+def restore_state(data: dict):
+ _identities.update(data.get("_identities", {}))
+ _config_sets.update(data.get("_config_sets", {}))
+ _ses_tags.update(data.get("_ses_tags", {}))
+
+
+_restored = load_state("ses_v2")
+if _restored:
+ restore_state(_restored)
+
+
def _json_err(code, message, status=400):
body = json.dumps({"message": message, "name": code}).encode("utf-8")
return status, {"Content-Type": "application/json"}, body
diff --git a/ministack/services/waf.py b/ministack/services/waf.py
index 7dd354f3..2cc0a0d1 100644
--- a/ministack/services/waf.py
+++ b/ministack/services/waf.py
@@ -9,10 +9,12 @@ Supports: CreateWebACL, GetWebACL, UpdateWebACL, DeleteWebACL, ListWebACLs,
CheckCapacity, DescribeManagedRuleGroup.
"""
+import copy
import json
import os
import logging
+from ministack.core.persistence import PERSIST_STATE, load_state
from ministack.core.responses import error_response_json, json_response, new_uuid, now_iso
logger = logging.getLogger("wafv2")
@@ -27,6 +29,29 @@ _associations: dict = {} # resource_arn -> webacl_arn
_waf_tags: dict = {} # resource_arn -> [tags]
+def get_state():
+ return copy.deepcopy({
+ "_web_acls": _web_acls,
+ "_ip_sets": _ip_sets,
+ "_rule_groups": _rule_groups,
+ "_associations": _associations,
+ "_waf_tags": _waf_tags,
+ })
+
+
+def restore_state(data):
+ _web_acls.update(data.get("_web_acls", {}))
+ _ip_sets.update(data.get("_ip_sets", {}))
+ _rule_groups.update(data.get("_rule_groups", {}))
+ _associations.update(data.get("_associations", {}))
+ _waf_tags.update(data.get("_waf_tags", {}))
+
+
+_restored = load_state("waf")
+if _restored:
+ restore_state(_restored)
+
+
def _waf_err(code, message):
return error_response_json(code, message, 400)
diff --git a/pyproject.toml b/pyproject.toml
index 732c2f4c..8106247e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "ministack"
-version = "1.1.39"
+version = "1.1.40"
description = "Free, open-source local AWS emulator — drop-in LocalStack replacement"
readme = "README.md"
license = { file = "LICENSE" }