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
feat(elasticache): add Valkey engine support (#1115)
Jason Camp99218622eeaf
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 681c6296..fa8e3647 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).## [Unreleased]### Added+- **ElastiCache — Valkey engine support** — `Engine=valkey` previously fell into the memcached branch of the container spawner: a nonexistent `memcached:<version>-alpine` image was requested, the spawn failed, and the cluster silently fell back to the shared sidecar advertising memcached's port 11211. `CreateCacheCluster` and `CreateReplicationGroup` now spawn a real `valkey/valkey:<major.minor>-alpine` container (AWS-supported versions 7.2, 8.0, 8.1) on port 6379, the no-Docker fallback advertises the Redis sidecar port, the default `EngineVersion` for valkey is `8.0` (previously memcached's `1.6.17`), and `DescribeCacheEngineVersions` lists valkey versions with their `valkey7`/`valkey8` parameter-group families (the `default.valkey*` groups already existed). `ELASTICACHE_CLUSTER_MODE_REAL` replication groups accept valkey too — the official valkey image ships `redis-*` compatibility symlinks, so the cluster bootstrap (`redis-cli --cluster create`) works unchanged.- **IoT — device shadow operations** — `GetThingShadow`, `UpdateThingShadow`, and `DeleteThingShadow` on the `iot-data` endpoint (classic and named shadows via `?name=`) previously returned `InvalidRequestException: Unsupported iot-data path: .../shadow`. Shadows now store `desired`/`reported` state: updates deep-merge into the stored document (a `null` value removes the field), bump the version, and stamp per-field `metadata` timestamps; the `/accepted` response echoes only the sections sent, while `GetThingShadow` returns the full document including the computed `state.delta` (desired fields that differ from reported). A stale `version` in an update is rejected with a `409`, and reading or deleting a nonexistent shadow returns `ResourceNotFoundException`. Shadows are account-scoped and persisted with the rest of the IoT state.- **KMS — `GenerateDataKeyPair` and `GenerateDataKeyPairWithoutPlaintext`** — the emulator implemented `GenerateDataKey` and `GenerateDataKeyWithoutPlaintext` but no data key *pair* operation, so both returned `InvalidAction: Unknown action`. These provision an asymmetric data key pair wrapped under a symmetric CMK: `GenerateDataKeyPair` returns `PrivateKeyPlaintext`, `PrivateKeyCiphertextBlob` and `PublicKey`, while the `WithoutPlaintext` variant omits `PrivateKeyPlaintext` so the private key never reaches the caller in the clear — the caller persists the ciphertext plus public key and nothing else. Supported `KeyPairSpec` values follow the real AWS enum — `RSA_2048/3072/4096`, `ECC_NIST_P256/P384/P521`, `ECC_SECG_P256K1`, `ECC_NIST_EDWARDS25519` (`SM2` is excluded, as `CreateKey` does not implement it either). Note this is a superset of what `CreateKey` accepts today: `CreateKey` still lacks `RSA_3072`, a pre-existing gap these operations do not share. The wrapping CMK must be symmetric, `EncryptionContext` binds the wrapped private key as it does for `Encrypt`, and the blob decrypts back to a PKCS#8 DER private key that pairs with the returned public key. The wrapped private key uses the emulator's ciphertext layout, now extended with a per-blob random nonce (`key_id(36) + context_hash(32) + nonce(16) + data`) that is mixed into key derivation; `Decrypt` reads these blobs exactly as it reads `Encrypt`'s and `GenerateDataKey`'s. The nonce is required for correctness of the `WithoutPlaintext` guarantee: without it the XOR keystream repeats across every blob sharing a CMK and `EncryptionContext`, and because a key pair's plaintext embeds its (public) modulus, the wrapped private key could be recovered from the public outputs alone. `Encrypt` and `GenerateDataKey` adopt the same nonced layout so all three wrap through an identical format.- **API Gateway v1 — `AWS::ApiGateway::GatewayResponse` CloudFormation support** — CDK/CloudFormation stacks that customize REST API errors such as `BAD_REQUEST_BODY`, `DEFAULT_4XX`, or `UNAUTHORIZED` now provision instead of rolling back with `Unsupported resource type`. The v1 control plane adds `PutGatewayResponse`, `GetGatewayResponse`, `GetGatewayResponses`, and `DeleteGatewayResponse`; customizations are account-scoped and persisted, mutable CFN properties update in place, `RestApiId`/`ResponseType` changes replace the resource, and deletion restores API Gateway's generated default response. Reported by @robert-pitt-foodhub (#1124).diff --git a/README.md b/README.mdindex 2967e1c6..ef1d88a9 100644--- a/README.md+++ b/README.md@@ -29,7 +29,7 @@ LocalStack recently moved its core services behind a paid plan. If you relied on- **Drop-in compatible** — works with `boto3`, AWS CLI, Terraform, CDK, Pulumi, any SDK- **Multi-account & multi-region** — a 12-digit access key becomes the account, the SigV4 region scopes the state; isolated tenants and regions on one endpoint, like real AWS- **Amazon Bedrock locally** — Converse / InvokeModel with AWS-exact wire shapes; point `MINISTACK_BEDROCK_PROXY_URL` at Ollama, llama.cpp, or vLLM and get real completions through the Bedrock API-- **Real infrastructure** — RDS spins up actual Postgres/MySQL containers, ElastiCache spins up real Redis, Athena runs real SQL via DuckDB (full image only), ECS runs real Docker containers+- **Real infrastructure** — RDS spins up actual Postgres/MySQL containers, ElastiCache spins up real Redis/Valkey, Athena runs real SQL via DuckDB (full image only), ECS runs real Docker containers- **Tiny footprint** — ~270MB image, ~30MB RAM at idle vs LocalStack's ~1GB image and ~500MB RAM- **Fast startup** — under 2 seconds, HTTP/2 (h2c) supported- **MIT licensed** — use it, fork it, contribute to it@@ -552,7 +552,7 @@ MiniStack expands AWS SAM transforms (`Transform: AWS::Serverless-2016-10-31`) i|---------|-----------|-------|| **ECS** | CreateCluster, DeleteCluster, DescribeClusters, ListClusters, UpdateCluster, UpdateClusterSettings, PutClusterCapacityProviders, RegisterTaskDefinition, DeregisterTaskDefinition, DescribeTaskDefinition, ListTaskDefinitions, ListTaskDefinitionFamilies, DeleteTaskDefinitions, CreateService, DeleteService, DescribeServices, UpdateService, ListServices, ListServicesByNamespace, RunTask, StopTask, DescribeTasks, ListTasks, ExecuteCommand, UpdateTaskProtection, GetTaskProtection, CreateCapacityProvider, UpdateCapacityProvider, DeleteCapacityProvider, DescribeCapacityProviders, TagResource, UntagResource, ListTagsForResource, ListAccountSettings, PutAccountSetting, PutAccountSettingDefault, DeleteAccountSetting, PutAttributes, DeleteAttributes, ListAttributes, DescribeServiceDeployments, ListServiceDeployments, DescribeServiceRevisions, SubmitTaskStateChange, SubmitContainerStateChange, SubmitAttachmentStateChanges, DiscoverPollEndpoint | 47 actions; `RunTask` starts real Docker containers via Docker socket; full Terraform ECS coverage || **RDS** | CreateDBInstance, DeleteDBInstance, DescribeDBInstances, ModifyDBInstance, StartDBInstance, StopDBInstance, RebootDBInstance, CreateDBInstanceReadReplica, RestoreDBInstanceFromDBSnapshot, CreateDBCluster, DeleteDBCluster, DescribeDBClusters, ModifyDBCluster, StartDBCluster, StopDBCluster, CreateDBSnapshot, DeleteDBSnapshot, DescribeDBSnapshots, CreateDBClusterSnapshot, DescribeDBClusterSnapshots, DeleteDBClusterSnapshot, CreateDBSubnetGroup, DeleteDBSubnetGroup, DescribeDBSubnetGroups, ModifyDBSubnetGroup, CreateDBParameterGroup, DeleteDBParameterGroup, DescribeDBParameterGroups, DescribeDBParameters, ModifyDBParameterGroup, CreateDBClusterParameterGroup, DescribeDBClusterParameterGroups, DeleteDBClusterParameterGroup, DescribeDBClusterParameters, ModifyDBClusterParameterGroup, CreateOptionGroup, DeleteOptionGroup, DescribeOptionGroups, DescribeOptionGroupOptions, ListTagsForResource, AddTagsToResource, RemoveTagsFromResource, DescribeDBEngineVersions, DescribeOrderableDBInstanceOptions, CreateGlobalCluster, DescribeGlobalClusters, DeleteGlobalCluster, RemoveFromGlobalCluster, ModifyGlobalCluster | `CreateDBInstance` spins up real Postgres/MySQL Docker container, returns actual `host:port` endpoint |-| **ElastiCache** | CreateCacheCluster, DeleteCacheCluster, DescribeCacheClusters, ModifyCacheCluster, RebootCacheCluster, CreateReplicationGroup, DeleteReplicationGroup, DescribeReplicationGroups, ModifyReplicationGroup, IncreaseReplicaCount, DecreaseReplicaCount, CreateCacheSubnetGroup, DescribeCacheSubnetGroups, ModifyCacheSubnetGroup, DeleteCacheSubnetGroup, CreateCacheParameterGroup, DescribeCacheParameterGroups, ModifyCacheParameterGroup, ResetCacheParameterGroup, DeleteCacheParameterGroup, DescribeCacheParameters, DescribeCacheEngineVersions, CreateUser, DescribeUsers, DeleteUser, ModifyUser, CreateUserGroup, DescribeUserGroups, DeleteUserGroup, ModifyUserGroup, ListTagsForResource, AddTagsToResource, RemoveTagsFromResource, CreateSnapshot, DeleteSnapshot, DescribeSnapshots, DescribeEvents | `CreateCacheCluster` spins up real Redis/Memcached Docker container |+| **ElastiCache** | CreateCacheCluster, DeleteCacheCluster, DescribeCacheClusters, ModifyCacheCluster, RebootCacheCluster, CreateReplicationGroup, DeleteReplicationGroup, DescribeReplicationGroups, ModifyReplicationGroup, IncreaseReplicaCount, DecreaseReplicaCount, CreateCacheSubnetGroup, DescribeCacheSubnetGroups, ModifyCacheSubnetGroup, DeleteCacheSubnetGroup, CreateCacheParameterGroup, DescribeCacheParameterGroups, ModifyCacheParameterGroup, ResetCacheParameterGroup, DeleteCacheParameterGroup, DescribeCacheParameters, DescribeCacheEngineVersions, CreateUser, DescribeUsers, DeleteUser, ModifyUser, CreateUserGroup, DescribeUserGroups, DeleteUserGroup, ModifyUserGroup, ListTagsForResource, AddTagsToResource, RemoveTagsFromResource, CreateSnapshot, DeleteSnapshot, DescribeSnapshots, DescribeEvents | `CreateCacheCluster` spins up a real Redis, Valkey, or Memcached Docker container (`Engine=redis`/`valkey`/`memcached`) || **Glue** | CreateDatabase, DeleteDatabase, GetDatabase, GetDatabases, UpdateDatabase, CreateTable, DeleteTable, GetTable, GetTables, UpdateTable, BatchDeleteTable, CreatePartition, DeletePartition, GetPartition, GetPartitions, BatchCreatePartition, BatchGetPartition, CreatePartitionIndex, GetPartitionIndexes, GetColumnStatisticsForTable, UpdateColumnStatisticsForTable, DeleteColumnStatisticsForTable, GetColumnStatisticsForPartition, UpdateColumnStatisticsForPartition, DeleteColumnStatisticsForPartition, CreateConnection, DeleteConnection, GetConnection, GetConnections, CreateCrawler, DeleteCrawler, GetCrawler, GetCrawlers, UpdateCrawler, StartCrawler, StopCrawler, GetCrawlerMetrics, CreateJob, DeleteJob, GetJob, GetJobs, UpdateJob, StartJobRun, GetJobRun, GetJobRuns, BatchStopJobRun, CreateTrigger, GetTrigger, DeleteTrigger, UpdateTrigger, StartTrigger, StopTrigger, ListTriggers, BatchGetTriggers, GetTriggers, CreateWorkflow, GetWorkflow, DeleteWorkflow, UpdateWorkflow, StartWorkflowRun, CreateUserDefinedFunction, UpdateUserDefinedFunction, DeleteUserDefinedFunction, GetUserDefinedFunction, GetUserDefinedFunctions, CreateSecurityConfiguration, DeleteSecurityConfiguration, GetSecurityConfiguration, GetSecurityConfigurations, CreateClassifier, GetClassifier, GetClassifiers, DeleteClassifier, TagResource, UntagResource, GetTags | Python shell jobs actually execute via subprocess; Spark jobs run on the official `amazon/aws-glue-libs` PySpark image (`GlueVersion: 4.0` / `3.0`) on MiniStack's Docker network; Glue-backed Iceberg REST catalog at `/iceberg` (signed with the `glue` credential scope, prefix `catalogs/{catalog}`) — read path for tables whose `metadata_location` parameter points at a metadata.json on MiniStack S3, e.g. DuckDB `ATTACH ... (TYPE iceberg, ENDPOINT 'localhost:4566/iceberg', AUTHORIZATION_TYPE 'sigv4')` with `USE_SSL=1` || **S3 Tables** | CreateTableBucket, ListTableBuckets, GetTableBucket, DeleteTableBucket, CreateNamespace, ListNamespaces, GetNamespace, DeleteNamespace, CreateTable, ListTables, GetTable, DeleteTable, GetTableMetadataLocation, UpdateTableMetadataLocation | Iceberg-format tables; embedded Iceberg REST catalog at `/iceberg` so Spark jobs (`spark.sql.catalog.*.type=rest`) can create / load / commit without an external catalog; data files in S3, metadata in memory || **Athena** | StartQueryExecution, GetQueryExecution, GetQueryResults, StopQueryExecution, ListQueryExecutions, BatchGetQueryExecution, CreateWorkGroup, DeleteWorkGroup, GetWorkGroup, ListWorkGroups, UpdateWorkGroup, CreateNamedQuery, DeleteNamedQuery, GetNamedQuery, ListNamedQueries, BatchGetNamedQuery, CreateDataCatalog, GetDataCatalog, ListDataCatalogs, DeleteDataCatalog, UpdateDataCatalog, CreatePreparedStatement, GetPreparedStatement, DeletePreparedStatement, ListPreparedStatements, GetTableMetadata, ListTableMetadata, TagResource, UntagResource, ListTagsForResource | Real SQL via **DuckDB** when installed (`pip install duckdb`), otherwise returns mock results; result pagination; column type metadata |@@ -654,6 +654,8 @@ print(r.get("key")) # b'value'A Redis sidecar is also always available at `localhost:6379` when using Docker Compose.+`Engine="valkey"` works the same way — a real `valkey/valkey` container is spawned (versions 7.2, 8.0, 8.1), the default parameter group becomes `default.valkey8`, and the advertised endpoint speaks the same protocol (`redis.Redis(...)` connects unchanged).+---## Athena with Real SQLdiff --git a/ministack/services/elasticache.py b/ministack/services/elasticache.pyindex ad8b5937..5909700b 100644--- a/ministack/services/elasticache.py+++ b/ministack/services/elasticache.py@@ -16,8 +16,8 @@ Supports: CreateCacheCluster, DeleteCacheCluster, DescribeCacheClusters,CreateSnapshot, DeleteSnapshot, DescribeSnapshots,DescribeEvents.-When Docker is available, CreateCacheCluster spins up a real Redis/Memcached container.-Otherwise returns localhost:6379 (assumes Redis sidecar in docker-compose).+When Docker is available, CreateCacheCluster spins up a real Redis/Valkey/Memcached+container. Otherwise returns localhost:6379 (assumes Redis sidecar in docker-compose)."""import copy@@ -412,15 +412,32 @@ def _get_docker():+def _engine_image_and_port(engine, engine_version):+ """Docker image and in-container port for a cache engine.++ Valkey images live under the ``valkey/`` Docker Hub org and tag by+ major.minor (AWS engine versions are two-part: 7.2, 8.0, 8.1); redis tags+ by major. The official valkey image ships ``redis-*`` compatibility+ symlinks, so the redis-cli readiness/bootstrap probes work unchanged.+ """+ if engine == "valkey":+ parts = [p for p in (engine_version or "").split(".") if p]+ tag = ".".join(parts[:2]) if len(parts) >= 2 else (parts[0] if parts else "8.0")+ return apply_image_prefix(f"valkey/valkey:{tag}-alpine"), 6379+ if engine == "redis":+ return apply_image_prefix(f"redis:{engine_version.split('.')[0]}-alpine"), 6379+ return apply_image_prefix(f"memcached:{engine_version}-alpine"), 11211++def _spawn_redis_container(name, engine, engine_version, labels):- """Start a redis/memcached container.+ """Start a redis/valkey/memcached container.Returns ``(host, port, container_id)``. On any failure (docker unavailable,image pull failed, etc.) returns ``(REDIS_DEFAULT_HOST, default_port, None)``so callers always have a usable endpoint shape — same fallback contract asthe original inline spawn block."""- default_port = REDIS_DEFAULT_PORT if engine == "redis" else 11211+ default_port = REDIS_DEFAULT_PORT if engine in ("redis", "valkey") else 11211docker_client = _get_docker()if not docker_client:return REDIS_DEFAULT_HOST, default_port, None@@ -430,12 +447,7 @@ def _spawn_redis_container(name, engine, engine_version, labels):endpoint_host = _MINISTACK_HOSTendpoint_port = host_port- if engine == "redis":- image = apply_image_prefix(f"redis:{engine_version.split('.')[0]}-alpine")- container_port = 6379- else:- image = apply_image_prefix(f"memcached:{engine_version}-alpine")- container_port = 11211+ image, container_port = _engine_image_and_port(engine, engine_version)try:run_kwargs = dict(@@ -467,8 +479,8 @@ def _spawn_redis_container(name, engine, engine_version, labels):return REDIS_DEFAULT_HOST, default_port, None-def _spawn_redis_cluster_node(name, engine_version, labels):- """Spawn a redis container with cluster-mode enabled.+def _spawn_redis_cluster_node(name, engine, engine_version, labels):+ """Spawn a redis/valkey container with cluster-mode enabled.Requires DOCKER_NETWORK to be set so nodes can reach each other on thecluster bus. Returns ``(container_ip, port, container_id)`` on success;@@ -481,8 +493,7 @@ def _spawn_redis_cluster_node(name, engine_version, labels):if not docker_client:return None, None, None- image = apply_image_prefix(f"redis:{engine_version.split('.')[0]}-alpine")- port = 6379+ image, port = _engine_image_and_port(engine, engine_version)cmd = ["redis-server","--cluster-enabled", "yes",@@ -585,7 +596,7 @@ def _teardown_containers(docker_client, container_ids):logger.warning("ElastiCache: cleanup failed for %s: %s", cid, e)-def _build_real_cluster_rg(rg_id, engine_version, num_node_groups, replicas_per_shard):+def _build_real_cluster_rg(rg_id, engine, engine_version, num_node_groups, replicas_per_shard):"""Spawn cluster-enabled nodes and run ``redis-cli --cluster create``.Returns ``(node_groups, container_ids)`` on success, or@@ -622,6 +633,7 @@ def _build_real_cluster_rg(rg_id, engine_version, num_node_groups, replicas_per_name = f"ministack-elasticache-rg-{account_id}-{region}-{rg_id}-{ng_id}-p"ip, port, cid = _spawn_redis_cluster_node(name=name,+ engine=engine,engine_version=engine_version,labels={**common_labels, "node_group": ng_id, "role": "primary"},)@@ -637,6 +649,7 @@ def _build_real_cluster_rg(rg_id, engine_version, num_node_groups, replicas_per_name = f"ministack-elasticache-rg-{account_id}-{region}-{rg_id}-{ng_id}-r{r}"ip, port, cid = _spawn_redis_cluster_node(name=name,+ engine=engine,engine_version=engine_version,labels={**common_labels,@@ -861,7 +874,7 @@ async def handle_request(method, path, headers, body, query_params):def _create_cache_cluster(p):cluster_id = _p(p, "CacheClusterId")engine = _p(p, "Engine") or "redis"- engine_version = _p(p, "EngineVersion") or ("7.0.12" if engine == "redis" else "1.6.17")+ engine_version = _p(p, "EngineVersion") or {"redis": "7.0.12", "valkey": "8.0"}.get(engine, "1.6.17")node_type = _p(p, "CacheNodeType") or "cache.t3.micro"num_nodes = int(_p(p, "NumCacheNodes") or "1")@@ -1020,7 +1033,7 @@ def _create_replication_group(p):desc = _p(p, "ReplicationGroupDescription") or ""node_type = _p(p, "CacheNodeType") or "cache.t3.micro"engine = _p(p, "Engine") or "redis"- engine_version = _p(p, "EngineVersion") or "7.0.12"+ engine_version = _p(p, "EngineVersion") or ("8.0" if engine == "valkey" else "7.0.12")num_node_groups = int(_p(p, "NumNodeGroups") or "1")num_cache_clusters = int(_p(p, "NumCacheClusters") or "1")replicas_per_node_group = int(_p(p, "ReplicasPerNodeGroup") or max(num_cache_clusters - 1, 0))@@ -1046,8 +1059,8 @@ def _create_replication_group(p):# Three paths for the spawn step:# (a) Real cluster-mode bootstrap — only when ALL of: num_node_groups>1,- # engine=redis, ELASTICACHE_CLUSTER_MODE_REAL=1, DOCKER_NETWORK set,- # docker reachable. Spawns N×(1+R) cluster-enabled nodes and runs+ # engine=redis/valkey, ELASTICACHE_CLUSTER_MODE_REAL=1, DOCKER_NETWORK+ # set, docker reachable. Spawns N×(1+R) cluster-enabled nodes and runs# ``redis-cli --cluster create`` so CLUSTER SLOTS is real.# (b) Per-shard fan-out — num_node_groups>=1 but cluster-mode prerequisites# not met. One container per shard, members within a shard share the@@ -1058,7 +1071,7 @@ def _create_replication_group(p):use_real_cluster = (num_node_groups > 1- and engine == "redis"+ and engine in ("redis", "valkey")and ELASTICACHE_CLUSTER_MODE_REALand DOCKER_NETWORKand _get_docker() is not None@@ -1074,7 +1087,7 @@ def _create_replication_group(p):if use_real_cluster:node_groups, container_ids = _build_real_cluster_rg(- rg_id, engine_version, num_node_groups, replicas_per_node_group,+ rg_id, engine, engine_version, num_node_groups, replicas_per_node_group,)if node_groups is None:# Bootstrap failed — clean up partial state and fall back.@@ -1662,7 +1675,11 @@ except Exception:def _describe_engine_versions(p):engine = _p(p, "Engine") or "redis"- versions = {"redis": ["7.1.0", "7.0.12", "6.2.14", "5.0.6"], "memcached": ["1.6.22", "1.6.17", "1.6.12"]}+ versions = {+ "redis": ["7.1.0", "7.0.12", "6.2.14", "5.0.6"],+ "valkey": ["8.1", "8.0", "7.2"],+ "memcached": ["1.6.22", "1.6.17", "1.6.12"],+ }# CacheEngineVersionList.member.locationName = "CacheEngineVersion"members = "".join(f"<CacheEngineVersion><Engine>{engine}</Engine><EngineVersion>{v}</EngineVersion>"diff --git a/tests/test_elasticache.py b/tests/test_elasticache.pyindex 4499e2bf..d972930a 100644--- a/tests/test_elasticache.py+++ b/tests/test_elasticache.py@@ -81,6 +81,44 @@ def test_elasticache_engines(ec):resp = ec.describe_cache_engine_versions(Engine="redis")assert len(resp["CacheEngineVersions"]) > 0+@requires_docker+def test_elasticache_valkey_engine_versions(ec):+ resp = ec.describe_cache_engine_versions(Engine="valkey")+ versions = resp["CacheEngineVersions"]+ assert len(versions) > 0+ assert all(v["Engine"] == "valkey" for v in versions)+ assert all(v["CacheParameterGroupFamily"].startswith("valkey") for v in versions)++@requires_docker+def test_elasticache_valkey_create_cluster(ec):+ ec.create_cache_cluster(+ CacheClusterId="test-valkey",+ Engine="valkey",+ EngineVersion="8.0",+ CacheNodeType="cache.t3.micro",+ NumCacheNodes=1,+ )+ resp = ec.describe_cache_clusters(CacheClusterId="test-valkey", ShowCacheNodeInfo=True)+ cluster = resp["CacheClusters"][0]+ assert cluster["Engine"] == "valkey"+ assert cluster["EngineVersion"] == "8.0"+ assert cluster["CacheParameterGroup"]["CacheParameterGroupName"] == "default.valkey8"+ # A real valkey container (or the redis-protocol fallback) — never memcached's port.+ assert cluster["CacheNodes"][0]["Endpoint"]["Port"] != 11211++@requires_docker+def test_elasticache_valkey_replication_group(ec):+ ec.create_replication_group(+ ReplicationGroupId="test-valkey-rg",+ ReplicationGroupDescription="Valkey replication group",+ Engine="valkey",+ CacheNodeType="cache.t3.micro",+ )+ resp = ec.describe_replication_groups(ReplicationGroupId="test-valkey-rg")+ rg = resp["ReplicationGroups"][0]+ assert rg["ReplicationGroupId"] == "test-valkey-rg"+ assert rg["NodeGroups"][0]["PrimaryEndpoint"]["Port"] != 11211+@requires_dockerdef test_elasticache_modify_subnet_group(ec):ec.create_cache_subnet_group(diff --git a/tests/test_elasticache_valkey.py b/tests/test_elasticache_valkey.pynew file mode 100644index 00000000..e96c9a7a--- /dev/null+++ b/tests/test_elasticache_valkey.py@@ -0,0 +1,44 @@+"""+Unit tests for ElastiCache Valkey engine support.++These test the engine → image/port mapping and the no-Docker fallback+directly — no running server or real Docker needed.+"""++from ministack.services import elasticache+from ministack.services.elasticache import _engine_image_and_port+++def _img(name):+ return elasticache.apply_image_prefix(name)+++def test_valkey_image_and_port():+ assert _engine_image_and_port("valkey", "8.0") == (_img("valkey/valkey:8.0-alpine"), 6379)+ assert _engine_image_and_port("valkey", "7.2") == (_img("valkey/valkey:7.2-alpine"), 6379)+ assert _engine_image_and_port("valkey", "8.1") == (_img("valkey/valkey:8.1-alpine"), 6379)+++def test_valkey_image_tag_truncates_patch_version():+ assert _engine_image_and_port("valkey", "7.2.6") == (_img("valkey/valkey:7.2-alpine"), 6379)+++def test_valkey_image_tag_defaults():+ assert _engine_image_and_port("valkey", "8") == (_img("valkey/valkey:8-alpine"), 6379)+ assert _engine_image_and_port("valkey", "") == (_img("valkey/valkey:8.0-alpine"), 6379)+++def test_redis_and_memcached_images_unchanged():+ assert _engine_image_and_port("redis", "7.1.0") == (_img("redis:7-alpine"), 6379)+ assert _engine_image_and_port("memcached", "1.6.17") == (_img("memcached:1.6.17-alpine"), 11211)+++def test_valkey_no_docker_fallback_uses_redis_port(monkeypatch):+ """Valkey previously fell into the memcached branch: nonexistent+ memcached:<ver>-alpine image, then a fallback advertising port 11211."""+ monkeypatch.setattr(elasticache, "_get_docker", lambda: None)+ host, port, cid = elasticache._spawn_redis_container(+ "ms-valkey-test", "valkey", "8.0", {"ministack": "elasticache"}+ )+ assert (host, port) == (elasticache.REDIS_DEFAULT_HOST, elasticache.REDIS_DEFAULT_PORT)+ assert cid is None