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
Fix SFN RDS global cluster member removal (#525)
Jay Janssenb01a47330891
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fdab8a97..1852d2c8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **S3 virtual-hosted and path-style integration tests** — `TestS3VhostGetPutObject` exercises both addressing styles end-to-end (simple and max-length dotted bucket names), `TestExtractS3VhostBucket` unit-tests the vhost extraction function, and `patch_endpoint_dns` lets virtual-hosted requests resolve against localhost in CI. `make_client` now accepts `additional_config_kwargs` for per-test SDK config overrides. Contributed by @mgius-ae.### Fixed+- **Step Functions `aws-sdk:rds:removeFromGlobalCluster` left global cluster members attached** — query-protocol parameter conversion uppercased `DbClusterIdentifier` to `DBClusterIdentifier`, but the RDS API shape for `RemoveFromGlobalCluster` intentionally uses `DbClusterIdentifier`. The task now preserves that member name so a successful remove actually detaches the cluster and a following `DeleteGlobalCluster` matches AWS behavior.- **S3 requests via custom `MINISTACK_HOST` hostname returned `NoSuchBucket`** — `_extract_s3_vhost_bucket` (introduced in 1.3.17) treated any dotted hostname as a virtual-hosted S3 URL, extracting the first label as a bucket name. Requests to `http://aws.private:4566` were misrouted as a vhost request for a bucket named `aws`. The function now checks the tail against `MINISTACK_HOST` and recognises all 18 documented AWS S3 virtual-hosted patterns (`s3`, `s3-accelerate`, `s3-fips`, `s3-accesspoint`, `s3-accesspoint-fips`, `s3-website`, `s3express-*`, and their dualstack/regional variants). Bare hostnames, IPv4 addresses, and `localhost` are correctly treated as path-style. Reported by @dsrosario.- **Glue `GetDatabase` returned `LocationUri: ""` when not set** — AWS specifies a minimum length of 1 for `LocationUri`, so the empty-string default violated the spec. Now returns `null` when the field is omitted from `CreateDatabase`. Contributed by @dcrn.- **Ruff linter not running on pull requests** — CI workflow trigger was missing the PR event.diff --git a/ministack/services/stepfunctions.py b/ministack/services/stepfunctions.pyindex 728a186c..6b85d58a 100644--- a/ministack/services/stepfunctions.py+++ b/ministack/services/stepfunctions.py@@ -2654,6 +2654,15 @@ _AWS_ACRONYMS = frozenset({"Tcp", "Udp", "Iops", "Ca", "Sg",})+# Most query-protocol RDS params expand SDK-style "Db" to wire-format "DB".+# RemoveFromGlobalCluster is the AWS-shape exception: its member is+# "DbClusterIdentifier", and sending "DBClusterIdentifier" is ignored.+_QUERY_PARAM_NAME_OVERRIDES = {+ ("rds", "RemoveFromGlobalCluster"): {+ "DbClusterIdentifier": "DbClusterIdentifier",+ },+}+def _sfn_key_to_api_name(name):"""Convert SFN SDK key name to AWS wire-format name.@@ -2669,12 +2678,19 @@ def _sfn_key_to_api_name(name):return "".join(t.upper() if t in _AWS_ACRONYMS else t for t in tokens)-def _convert_params_to_api_names(data):+def _convert_params_to_api_names(data, name_overrides=None):"""Recursively convert SFN SDK-style param names to AWS wire-format names."""if isinstance(data, dict):- return {_sfn_key_to_api_name(k): _convert_params_to_api_names(v) for k, v in data.items()}+ converted = {}+ for key, value in data.items():+ if name_overrides and key in name_overrides:+ wire_key = name_overrides[key]+ else:+ wire_key = _sfn_key_to_api_name(key)+ converted[wire_key] = _convert_params_to_api_names(value, name_overrides)+ return convertedif isinstance(data, list):- return [_convert_params_to_api_names(item) for item in data]+ return [_convert_params_to_api_names(item, name_overrides) for item in data]return data@@ -2751,7 +2767,8 @@ def _dispatch_aws_sdk_query(service_info, service_name, action, input_data):pascal_action = action[0].upper() + action[1:] if action else action# Convert SFN SDK-style param names (DbSubnetGroupName) to wire-format# names (DBSubnetGroupName) before flattening to query params.- wire_data = _convert_params_to_api_names(input_data)+ name_overrides = _QUERY_PARAM_NAME_OVERRIDES.get((service_key, pascal_action))+ wire_data = _convert_params_to_api_names(input_data, name_overrides)form_params = {"Action": pascal_action}form_params.update(_flatten_query_params(wire_data))body = urlencode(form_params)diff --git a/tests/test_sfn.py b/tests/test_sfn.pyindex 7bc6c34c..bb19bbbb 100644--- a/tests/test_sfn.py+++ b/tests/test_sfn.py@@ -782,6 +782,76 @@ def test_sfn_aws_sdk_rds_modify_cluster(sfn, sfn_sync, rds):sfn_sync.delete_state_machine(stateMachineArn=sm_arn)+def test_sfn_aws_sdk_rds_remove_from_global_cluster(sfn, sfn_sync, rds):+ """aws-sdk:rds RemoveFromGlobalCluster preserves RDS' DbClusterIdentifier shape."""+ cluster_id = f"sfn-global-{_uuid_mod.uuid4().hex[:8]}"+ global_id = f"sfn-global-{_uuid_mod.uuid4().hex[:8]}"+ sm_name = f"sdk-rds-global-{_uuid_mod.uuid4().hex[:8]}"+ sm_arn = None++ rds.create_db_cluster(+ DBClusterIdentifier=cluster_id,+ Engine="aurora-postgresql",+ MasterUsername="admin",+ MasterUserPassword="testpass123",+ )+ rds.create_global_cluster(+ GlobalClusterIdentifier=global_id,+ SourceDBClusterIdentifier=cluster_id,+ )++ definition = json.dumps({+ "StartAt": "RemovePrimary",+ "States": {+ "RemovePrimary": {+ "Type": "Task",+ "Resource": "arn:aws:states:::aws-sdk:rds:removeFromGlobalCluster",+ "Parameters": {+ "GlobalClusterIdentifier": global_id,+ "DbClusterIdentifier": cluster_id,+ },+ "ResultPath": "$.removeResult",+ "Next": "DeleteGlobal",+ },+ "DeleteGlobal": {+ "Type": "Task",+ "Resource": "arn:aws:states:::aws-sdk:rds:deleteGlobalCluster",+ "Parameters": {+ "GlobalClusterIdentifier": global_id,+ },+ "ResultPath": "$.deleteResult",+ "End": True,+ },+ },+ })++ try:+ 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({}))+ assert resp["status"] == "SUCCEEDED", f"Execution failed: {resp.get('error')} — {resp.get('cause')}"+ output = json.loads(resp["output"])+ assert output["removeResult"]["GlobalCluster"]["GlobalClusterMembers"] == []+ finally:+ if sm_arn:+ sfn_sync.delete_state_machine(stateMachineArn=sm_arn)+ try:+ rds.remove_from_global_cluster(+ GlobalClusterIdentifier=global_id,+ DbClusterIdentifier=cluster_id,+ )+ except ClientError:+ pass+ try:+ rds.delete_global_cluster(GlobalClusterIdentifier=global_id)+ except ClientError:+ pass+ rds.delete_db_cluster(DBClusterIdentifier=cluster_id, SkipFinalSnapshot=True)+def test_sfn_xml_list_wrapper_single_element(sfn, sfn_sync):"""DescribeDBClusters returns a JSON list even when only one cluster exists."""import uuid as _uuid