Skip to content

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

fix(rds, cfn): message in clusters, custom names (#1454)

Nahuel Nuceraa05ddb936b01
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e354cb20..37455399 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@ Versioning follows [Semantic Versioning](https://semver.org/).
## [Unreleased]
### Fixed
+- **Step Functions — an unimplemented optimized service integration now fails the execution instead of silently succeeding** — a Task using an `arn:aws:states:::<service>:<action>` integration MiniStack does not implement fell through to echoing its input back as a `SUCCEEDED` result, so a state machine whose side effect never ran still reported success. Such a task now fails with `States.Runtime` naming the unimplemented resource; implemented integrations and the generic `aws-sdk:` form are unaffected. Reported by @iwasakar.
+- **CloudFormation — an update that would replace a custom-named resource is refused instead of silently executing and destroying data** — a stack update requiring replacement of a resource with an explicit physical name (for example changing a DynamoDB key attribute's type on a table that sets `TableName`) executed the replacement, reported `UPDATE_COMPLETE`, and dropped the table's rows. Such an update now fails and rolls back to `UPDATE_ROLLBACK_COMPLETE` with the message real CloudFormation uses (`CloudFormation cannot update a stack when a custom-named resource requires replacing. Rename <name> and update the stack again.`), leaving the resource and its data untouched; renaming the resource is still the way to force the replacement. Reported by @iot-rocket.
- **RDS — Aurora engine versions are validated on non-create writes and global inheritance** — `ModifyDBInstance`, `ModifyDBCluster`, `CreateGlobalCluster`, and `ModifyGlobalCluster` stored arbitrary Aurora engine versions that the shared engine catalog did not advertise, and `CreateDBCluster` could inherit such a version from legacy global-cluster state even though supplying it explicitly was rejected. All paths now use the shared catalog validator and reject unknown versions before mutating any state: create paths keep the create-time `Cannot find version {version} for {engine}`, while the modify paths report the upgrade-target shape real AWS uses (`InvalidParameterCombination` / `Cannot find upgrade target from {current} with requested version {requested}.`, as seen in real `ModifyDBCluster` transcripts). `ModifyGlobalCluster` now also propagates an accepted version to every member cluster the way real AWS applies global-database version changes, and `ModifyDBCluster` refuses to move a member cluster to a different major than its global cluster — the combination `CreateDBCluster` already refuses to produce. Contributed by @kiran01bm.
### Added
- **RDS — replicated Aurora PostgreSQL readers survive StopDBCluster / StartDBCluster and warm boot** — stopping a cluster with replicating readers was refused with `InvalidDBClusterStateFault` (the follow-up slice of #1325 the reader feature shipped without), and a MiniStack restart demoted a persisted reader to an alias of the writer's shared container. `StopDBCluster` now stops the writer's container and every reader-owned standby container — a stop that fails on any of them rolls back what it stopped and reports the failure instead of publishing `stopped` — and `StartDBCluster` restarts the writer, waits for it to accept authenticated connections, then revives each reader by re-cloning from the writer at its current address, keeping the member's identity, endpoint, and volume name (reader compute owns no durable state, as on Aurora, so revival recreates the container rather than restarting it). The same revival runs on warm boot. A revival that genuinely fails lands the cluster back on `stopped` for retry; only when compute deliberately cannot come back (control-plane-only restore, or the replication flag withdrawn between runs) does the member fall back to aliasing the writer, releasing its former container and volume, instead of advertising an endpoint nothing serves. Contributed by @kiran01bm.
diff --git a/README.md b/README.md
index 4686d382..65495749 100644
--- a/README.md
+++ b/README.md
@@ -536,7 +536,7 @@ subnet = ec2.create_subnet(
| `AWS::ApiGatewayV2::Integration` | Integration ID | IntegrationId |
| `AWS::ApiGatewayV2::Route` | Route ID | RouteId |
| `AWS::SES::EmailIdentity` | Identity | EmailIdentity |
-| `AWS::SES::ConfigurationSet` | Configuration set name | Id |
+| `AWS::SES::ConfigurationSet` | Configuration set name | None |
| `AWS::SES::ConfigurationSetEventDestination` | Event destination ID | Id |
| `AWS::WAFv2::WebACL` | WebACL ID | Arn, Id |
| `AWS::CloudFront::Distribution` | Distribution ID | Arn, DomainName, Id |
diff --git a/ministack/services/cloudformation/provisioners.py b/ministack/services/cloudformation/provisioners.py
index 68a73eb1..35513efc 100644
--- a/ministack/services/cloudformation/provisioners.py
+++ b/ministack/services/cloudformation/provisioners.py
@@ -151,6 +151,60 @@ def _delete_resource(resource_type: str, physical_id: str, props: dict,
resource_type, physical_id)
+def _requires_replacement_dynamodb(old_props, new_props):
+ """AWS::DynamoDB::Table requires replacement when an existing attribute's
+ type changes (AWS docs: "Changing the type of an existing
+ AttributeDefinition requires replacement of the table")."""
+ old_types = {
+ a.get("AttributeName"): a.get("AttributeType")
+ for a in old_props.get("AttributeDefinitions", [])
+ if isinstance(a, dict) and a.get("AttributeName")
+ }
+ for a in new_props.get("AttributeDefinitions", []):
+ if not isinstance(a, dict):
+ continue
+ name = a.get("AttributeName")
+ if name in old_types and old_types[name] != a.get("AttributeType"):
+ return True
+ return False
+
+
+# Resource types that carry a user-supplied physical name AND can require
+# replacement. Real CloudFormation refuses an update that would replace a
+# custom-named resource (you must rename it first), so MiniStack must fail the
+# update instead of silently executing the replacement and destroying data
+# (issue #1433).
+_CUSTOM_NAME_REPLACEMENT = {
+ "AWS::DynamoDB::Table": {
+ "name": "TableName",
+ "requires_replacement": _requires_replacement_dynamodb,
+ },
+}
+
+
+def _custom_named_replacement_error(resource_type, old_props, new_props):
+ """Return the real-AWS error when a stack update would replace a
+ custom-named resource, else None.
+
+ Only an explicit, unchanged physical name is blocked: renaming is AWS's
+ sanctioned escape hatch (the replacement proceeds under the new name), and
+ an auto-generated name can always be replaced.
+ """
+ spec = _CUSTOM_NAME_REPLACEMENT.get(resource_type)
+ if not spec:
+ return None
+ old_name = old_props.get(spec["name"])
+ new_name = new_props.get(spec["name"])
+ if not old_name or old_name != new_name:
+ return None
+ if spec["requires_replacement"](old_props, new_props):
+ return (
+ "CloudFormation cannot update a stack when a custom-named resource "
+ f"requires replacing. Rename {old_name} and update the stack again."
+ )
+ return None
+
+
def _update_resource(resource_type: str, physical_id: str, old_props: dict,
new_props: dict, stack_name: str,
logical_id: str | None = None,
@@ -174,6 +228,11 @@ def _update_resource(resource_type: str, physical_id: str, old_props: dict,
# still referencing it via Ref/Fn::GetAtt would then pick up the
# instant it was reprocessed later in the same update.
return physical_id, old_attrs or {}
+ replacement_error = _custom_named_replacement_error(
+ resource_type, old_props, new_props
+ )
+ if replacement_error:
+ raise ValueError(replacement_error)
handler = _RESOURCE_HANDLERS.get(resource_type)
if handler and "update" in handler:
if handler.get("update_with_logical_id"):
@@ -5211,7 +5270,9 @@ def _ses_configuration_set_create(logical_id, props, stack_name):
"CreatedTimestamp": _ses._iso_now(),
}
_ses_v2._config_sets[name] = {"ConfigurationSetName": name, "Tags": []}
- return name, {"Id": name}
+ # Real AWS AWS::SES::ConfigurationSet supports Ref (the set name) only; it
+ # exposes no Fn::GetAtt attributes, so return none.
+ return name, {}
def _ses_configuration_set_delete(physical_id, props):
diff --git a/ministack/services/rds.py b/ministack/services/rds.py
index 94b83266..b735398e 100644
--- a/ministack/services/rds.py
+++ b/ministack/services/rds.py
@@ -4389,9 +4389,11 @@ def _create_db_cluster(p):
expected_engine = global_cluster.get("Engine")
if _p(p, "Engine") and expected_engine and engine != expected_engine:
return _error(
+ # Real AWS message shape (InvalidParameterValue, Sender, 400),
+ # verbatim template from a captured CreateDBCluster transcript.
"InvalidParameterValue",
- f"Engine {engine} is incompatible with global cluster "
- f"{global_cluster_id} engine {expected_engine}.",
+ "Value for engine should match setting for global cluster "
+ f"{global_cluster_id}",
400,
)
engine = expected_engine or engine
@@ -4413,9 +4415,11 @@ def _create_db_cluster(p):
and engine_version != expected_engine_version
):
return _error(
+ # Verbatim real-AWS message (InvalidParameterValue, Sender, 400)
+ # from a captured CreateDBCluster-into-global transcript.
"InvalidParameterValue",
- f"EngineVersion {engine_version} is incompatible with global "
- f"cluster {global_cluster_id} engine version {expected_engine_version}.",
+ "Value for engineVersion should match setting for global "
+ f"cluster {global_cluster_id}",
400,
)
engine_version = expected_engine_version or engine_version
@@ -7344,9 +7348,9 @@ def _global_member_engine_version_conflict_error(cluster, engine_version):
if not requested_major or not global_major or requested_major == global_major:
return None
return _error(
- "InvalidParameterValue",
- f"EngineVersion {engine_version} is incompatible with global "
- f"cluster {gc_id} engine version {gc_version}.",
+ "InvalidParameterCombination",
+ "Major Version Upgrade isn't supported in a single member of a "
+ "global cluster. Use ModifyGlobalCluster to upgrade all the members.",
400,
)
diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.py
index 80f72338..b5b14f7e 100644
--- a/ministack/services/stepfunctions.py
+++ b/ministack/services/stepfunctions.py
@@ -1567,6 +1567,20 @@ def _invoke_resource(resource, input_data):
if "aws-sdk:" in resource:
return _invoke_aws_sdk_integration(resource, input_data)
+ # An optimized service integration (arn:aws:states:::<service>:<action>)
+ # that reaches here is one MiniStack does not implement. Real AWS supports
+ # every documented optimized integration, so echoing the input back as a
+ # SUCCEEDED result hides a genuine gap (a state machine "passes" locally
+ # while its side effect never happens). Fail loudly instead, mirroring the
+ # aws-sdk dispatcher's "not yet implemented" failure.
+ if resource.startswith("arn:aws:states:::"):
+ raise _ExecutionError(
+ "States.Runtime",
+ f"{resource} is not yet implemented in MiniStack. Use the generic "
+ "arn:aws:states:::aws-sdk:<service>:<action> form, or open an issue "
+ "for this optimized integration.",
+ )
+
return input_data
diff --git a/tests/test_cfn.py b/tests/test_cfn.py
index a4ca62ca..01c2dfb7 100644
--- a/tests/test_cfn.py
+++ b/tests/test_cfn.py
@@ -803,6 +803,65 @@ def test_cfn_unnamed_dynamodb_table_survives_unrelated_update(cfn, ddb, ssm):
assert table_name_after == table_name_before, "the table was re-created under a new name"
assert table_name_after in tables_after, "the stack's table did not survive the update"
+def test_cfn_custom_named_table_replacement_refused_data_survives(cfn, ddb):
+ """A stack update that requires replacing a custom-named DynamoDB table
+ (changing a key attribute's type S->N) is refused exactly as real
+ CloudFormation refuses it: the stack rolls back to UPDATE_ROLLBACK_COMPLETE
+ with the "custom-named resource requires replacing" message, and the table
+ and its data survive untouched instead of being silently replaced (#1433)."""
+ def template(sk_type):
+ return json.dumps({
+ "AWSTemplateFormatVersion": "2010-09-09",
+ "Resources": {
+ "T": {
+ "Type": "AWS::DynamoDB::Table",
+ "Properties": {
+ "TableName": "cfn_named_probe_1433",
+ "BillingMode": "PAY_PER_REQUEST",
+ "AttributeDefinitions": [
+ {"AttributeName": "pk", "AttributeType": "S"},
+ {"AttributeName": "sk", "AttributeType": sk_type},
+ ],
+ "KeySchema": [
+ {"AttributeName": "pk", "KeyType": "HASH"},
+ {"AttributeName": "sk", "KeyType": "RANGE"},
+ ],
+ },
+ },
+ },
+ })
+
+ cfn.create_stack(StackName="cfn-1433", TemplateBody=template("S"))
+ _wait_stack(cfn, "cfn-1433")
+ try:
+ ddb.put_item(TableName="cfn_named_probe_1433",
+ Item={"pk": {"S": "row"}, "sk": {"S": "keep-me"}})
+
+ # sk type S->N requires replacing the table; AWS refuses because the
+ # table carries a custom name.
+ cfn.update_stack(StackName="cfn-1433", TemplateBody=template("N"))
+ stack = _wait_stack(cfn, "cfn-1433")
+ assert stack["StackStatus"] == "UPDATE_ROLLBACK_COMPLETE"
+
+ # Schema unchanged: sk is still S.
+ attrs = ddb.describe_table(
+ TableName="cfn_named_probe_1433")["Table"]["AttributeDefinitions"]
+ sk = next(a for a in attrs if a["AttributeName"] == "sk")
+ assert sk["AttributeType"] == "S"
+
+ # The seeded row is intact.
+ assert ddb.scan(TableName="cfn_named_probe_1433")["Count"] == 1
+
+ # The refusal names the real AWS reason.
+ events = cfn.describe_stack_events(
+ StackName="cfn-1433")["StackEvents"]
+ reasons = " ".join(
+ e.get("ResourceStatusReason", "") for e in events)
+ assert "custom-named resource requires replacing" in reasons
+ finally:
+ cfn.delete_stack(StackName="cfn-1433")
+
+
def test_cfn_ssm_parameter_value_type_resolves_stored_value(cfn, ssm, sqs):
"""A `AWS::SSM::Parameter::Value<String>` template parameter's Default/
provided value is an SSM parameter *name*, not the value itself — real
diff --git a/tests/test_rds.py b/tests/test_rds.py
index 6dc79b88..a8bdaf1b 100644
--- a/tests/test_rds.py
+++ b/tests/test_rds.py
@@ -1487,11 +1487,10 @@ def test_rds_modify_global_cluster_applies_version_to_members(rds):
DBClusterIdentifier=member_id,
EngineVersion="15.13",
)
- assert exc.value.response["Error"]["Code"] == "InvalidParameterValue"
- assert (
- exc.value.response["Error"]["Message"]
- == "EngineVersion 15.13 is incompatible with global cluster "
- f"{global_id} engine version 16.9."
+ assert exc.value.response["Error"]["Code"] == "InvalidParameterCombination"
+ assert exc.value.response["Error"]["Message"] == (
+ "Major Version Upgrade isn't supported in a single member of a "
+ "global cluster. Use ModifyGlobalCluster to upgrade all the members."
)
# Minor upgrades within the same major stay allowed per member.
@@ -1512,6 +1511,38 @@ def test_rds_modify_global_cluster_applies_version_to_members(rds):
rds.delete_global_cluster(GlobalClusterIdentifier=global_id)
+def test_rds_create_db_cluster_global_member_version_mismatch(rds):
+ """CreateDBCluster into a global cluster with a different EngineVersion is
+ rejected with the real-AWS shape: InvalidParameterValue / "Value for
+ engineVersion should match setting for global cluster <name>" (captured
+ verbatim from a live CreateDBCluster transcript)."""
+ import uuid as _uuid
+ global_id = f"create-mismatch-{_uuid.uuid4().hex[:8]}"
+ member_id = f"{global_id}-member"
+ rds.create_global_cluster(
+ GlobalClusterIdentifier=global_id,
+ Engine="aurora-postgresql",
+ EngineVersion="16.8",
+ )
+ try:
+ with pytest.raises(ClientError) as exc:
+ rds.create_db_cluster(
+ DBClusterIdentifier=member_id,
+ Engine="aurora-postgresql",
+ EngineVersion="15.13",
+ GlobalClusterIdentifier=global_id,
+ MasterUsername="admin",
+ MasterUserPassword="password123",
+ )
+ assert exc.value.response["Error"]["Code"] == "InvalidParameterValue"
+ assert exc.value.response["Error"]["Message"] == (
+ "Value for engineVersion should match setting for global "
+ f"cluster {global_id}"
+ )
+ finally:
+ rds.delete_global_cluster(GlobalClusterIdentifier=global_id)
+
+
def test_rds_aurora_postgresql_create_global_cluster_rejects_engine_version(rds):
with pytest.raises(ClientError) as exc:
rds.create_global_cluster(
diff --git a/tests/test_stepfunctions.py b/tests/test_stepfunctions.py
index 15b30f94..e6e951ee 100644
--- a/tests/test_stepfunctions.py
+++ b/tests/test_stepfunctions.py
@@ -3094,6 +3094,36 @@ def test_sfn_integration_events_put_events(sfn, eb, sqs):
assert got is not None, "event was not delivered to the EventBridge target"
assert "sfn.pipeline" in got
+
+def test_sfn_unimplemented_optimized_integration_fails_loudly(sfn_sync):
+ """An optimized service integration MiniStack does not implement must FAIL
+ the execution, not silently echo the input back as SUCCEEDED (#1443
+ follow-up: the dispatch fall-through used to `return input_data`)."""
+ import uuid as _uuid
+ sm_name = f"sfn-unimpl-opt-{_uuid.uuid4().hex[:8]}"
+ definition = json.dumps({
+ "StartAt": "Unimplemented",
+ "States": {
+ "Unimplemented": {
+ "Type": "Task",
+ "Resource": "arn:aws:states:::glue:startJobRun",
+ "Parameters": {"JobName": "etl"},
+ "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({}))
+ # Must not be the silent-success echo of the input.
+ assert resp["status"] == "FAILED"
+ blob = (resp.get("cause", "") + resp.get("error", "")).lower()
+ assert "not yet implemented" in blob or "glue:startjobrun" in blob
+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)
+
def test_sfn_integration_sqs_send_message_wait_for_task_token(sfn, sqs):
"""sqs:sendMessage.waitForTaskToken must actually deliver the message
(carrying the task token, serialised to JSON) and resume on