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(rds): add control plane for dbproxy + glue fix (#1502)
Nahuel Nucera97b0a80ccd8b
diff --git a/.github/workflows/docker-publish-on-pr.yml b/.github/workflows/docker-publish-on-pr.ymlindex c28e460c..de010703 100644--- a/.github/workflows/docker-publish-on-pr.yml+++ b/.github/workflows/docker-publish-on-pr.yml@@ -6,6 +6,10 @@ on:env:DOCKERHUB_IMAGE_ORG: ministackorg/ministack-preview-build+ # Suppress docker/build-push-action's auto-generated build summary and the+ # .dockerbuild record artifact — noise on PR preview builds.+ DOCKER_BUILD_SUMMARY: "false"+ DOCKER_BUILD_RECORD_UPLOAD: "false"jobs:publish-pr:@@ -39,7 +43,7 @@ jobs:- name: Comment that auto-preview was skippedif: steps.guard.outputs.skip == 'true'- uses: peter-evans/create-or-update-comment@v4+ uses: peter-evans/create-or-update-comment@v5with:token: ${{ secrets.GITHUB_TOKEN }}issue-number: ${{ github.event.pull_request.number }}@@ -72,6 +76,11 @@ jobs:- name: Set up QEMU (multi-arch)if: steps.guard.outputs.skip != 'true'uses: docker/setup-qemu-action@v4+ with:+ # pull_request_target gets a read-only Actions cache, so caching the+ # binfmt image fails with "cache write denied". Skip it — binfmt just+ # reinstalls each run (a couple seconds), no warning.+ cache-image: false- name: Set up Docker Buildxif: steps.guard.outputs.skip != 'true'@@ -146,7 +155,7 @@ jobs:- name: Comment on PR with Docker image infoif: steps.guard.outputs.skip != 'true'- uses: peter-evans/create-or-update-comment@v4+ uses: peter-evans/create-or-update-comment@v5with:token: ${{ secrets.GITHUB_TOKEN }}issue-number: ${{ github.event.pull_request.number }}diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 043fba07..65cf0603 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -11,6 +11,7 @@ Versioning follows [Semantic Versioning](https://semver.org/).- **S3 — a presigned upload no longer drops the `x-amz-*` headers it was signed with** — a presigned URL is sent by a caller who has only the URL and a body, so SigV4 lets the `x-amz-*` headers an operation asked for be hoisted into the query string, where the signature covers them exactly as a signed header would. SDKs presign that way and real S3 applies those params as the headers they stand for. MiniStack only ever read headers, so a presigned `PutObject` carrying user metadata in its query string answered `200` and stored the object with no metadata at all. Hoisted `x-amz-*` params are now folded back into the request headers before routing (user metadata, storage class, tagging, ACL, SSE and copy source) while an explicitly sent header still wins over its hoisted twin, and the SigV4 signing params are never mistaken for one. Contributed by @dennmart.- **CloudFormation — `Fn::Sub` honors the `${!Literal}` escape** — the leading `!` was not recognized, so the name fell through every lookup and rendered as `!Literal` with the braces consumed; `${!Literal}` now renders as the literal `${Literal}` and no longer registers a dependency on a resource of that name. An `AWS::IoT::Policy` pinned to `${!iot:Connection.Thing.ThingName}` deployed with a document matching nothing, so the policy denied every connect, publish and subscribe while the stack still reported `CREATE_COMPLETE`. Reported by @iot-rocket.### Added+- **RDS — RDS Proxy (control plane)** — `CreateDBProxy` and the twelve other proxy operations answered `InvalidAction`, so a Terraform, CloudFormation or Crossplane definition of an `aws_db_proxy` could not be applied at all. Proxies, proxy endpoints, the default target group and registered instance and cluster targets now create, describe, modify and delete with the documented shapes, defaults (`IdleClientTimeout` 1800, `MaxConnectionsPercent` 100 or 10 on SQL Server, `ConnectionBorrowTimeout` 120) and faults (`DBProxyAlreadyExistsFault`, `DBProxyNotFoundFault`, `DBProxyEndpointNotFoundFault`, `DBProxyTargetGroupNotFoundFault`, `DBProxyTargetAlreadyRegisteredFault`, `DBProxyQuotaExceededFault`, `DBProxyEndpointQuotaExceededFault`, `InvalidDBProxyEndpointStateFault`, `InvalidSubnet`). Creating a proxy also creates its default read/write endpoint and its `default` target group, as AWS does; the default endpoint refuses modification and deletion, `Marker` / `MaxRecords` paginate, and the documented constraints are enforced (`IdleClientTimeout` 1-28,800, `MaxConnectionsPercent` 1-100, `ConnectionBorrowTimeout` 0-300, `MaxIdleConnectionsPercent` between 0 and `MaxConnectionsPercent` and defaulting to half of it, `Auth` required unless `DefaultAuthScheme` is `IAM_AUTH`, one target per proxy, and a target whose engine the proxy's `EngineFamily` supports). This is metadata only: no connection pooling happens and nothing listens on the proxy endpoint hostname. Reported by @jmreicha.- **EC2 — opt-in launch options for instance containers (`EC2_DOCKER_FLAGS`)** — a registered image that boots an operating system (systemd as PID 1) needs container options the fixed launch arguments cannot express: unprivileged, `unshare` fails with `Operation not permitted` and the instance terminates at boot. `EC2_DOCKER_FLAGS` now takes a docker-CLI-style string (`--privileged`, `--cap-add`, `-e`, `-v`, `--tmpfs`, `--add-host`, `-m`, `--shm-size`) applied to every instance container; unset, nothing changes. `--init` is refused — instance containers always run with init. Contributed by @iot-rocket.### Fixed- **EventBridge — dotted pattern keys resolve to the nested path** — [Event Ruler](https://github.com/aws/event-ruler) joins keys with `.` when compiling, so `{"detail.name": [...]}` and `{"detail": {"name": [...]}}` are the same sub-rule on AWS (verified with `TestEventPattern` against the real service); the 1.4 matcher rewrite read a dotted key as one literal segment, so such a rule silently matched nothing — consumer rules written in the dotted form delivered on 1.3.x and stopped after upgrading. Pattern keys are now split on `.` when the compiler extends the path, composing with `$or` expansion, value-side operators, and leaf/object collision handling. The residual divergence — an event *field* literally named `a.b` flattens to the same path on AWS but stays one key here — remains pinned by test; Ruler documents that collision as behaviour that "should not be relied upon". Contributed by @prandogabriel.diff --git a/README.md b/README.mdindex 92265c89..96347989 100644--- a/README.md+++ b/README.md@@ -563,7 +563,7 @@ MiniStack expands AWS SAM transforms (`Transform: AWS::Serverless-2016-10-31`) i| Service | Operations | Notes ||---------|-----------|-------|| **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, FailoverDBCluster, 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; Aurora MySQL 8.0/8.4 compatibility objects (`AWSAuthenticationPlugin`, RDS/Aurora stored procedures, predefined S3 roles) install automatically for supported MySQL images so Aurora provisioning workflows run — the plugin rejects authentication (non-enforcing); disable with `MINISTACK_MYSQL_IAM_AUTH=off` |+| **RDS** | CreateDBInstance, DeleteDBInstance, DescribeDBInstances, ModifyDBInstance, StartDBInstance, StopDBInstance, RebootDBInstance, CreateDBInstanceReadReplica, RestoreDBInstanceFromDBSnapshot, CreateDBCluster, DeleteDBCluster, DescribeDBClusters, ModifyDBCluster, StartDBCluster, StopDBCluster, FailoverDBCluster, 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, CreateDBProxy, DescribeDBProxies, ModifyDBProxy, DeleteDBProxy, CreateDBProxyEndpoint, DescribeDBProxyEndpoints, ModifyDBProxyEndpoint, DeleteDBProxyEndpoint, DescribeDBProxyTargetGroups, ModifyDBProxyTargetGroup, RegisterDBProxyTargets, DeregisterDBProxyTargets, DescribeDBProxyTargets | `CreateDBInstance` spins up real Postgres/MySQL Docker container, returns actual `host:port` endpoint; Aurora MySQL 8.0/8.4 compatibility objects (`AWSAuthenticationPlugin`, RDS/Aurora stored procedures, predefined S3 roles) install automatically for supported MySQL images so Aurora provisioning workflows run — the plugin rejects authentication (non-enforcing); disable with `MINISTACK_MYSQL_IAM_AUTH=off`. RDS Proxy is control plane only — proxies, proxy endpoints, the default target group and registered targets are stored and returned with the AWS shapes, but nothing listens on the proxy endpoint hostname; clients keep connecting to the instance or cluster endpoint || **Aurora DSQL** | CreateCluster, GetCluster, UpdateCluster, DeleteCluster, ListClusters, PutClusterPolicy, GetClusterPolicy, DeleteClusterPolicy, TagResource, UntagResource, ListTagsForResource | `CreateCluster` spins up a real `postgres:16-alpine` Docker container fronted by a validating PG wire-protocol proxy that **fails like real DSQL** — rejects unsupported SQL (`serial`, foreign keys, extensions, ...), accepts `CREATE INDEX ASYNC` + `sys.jobs`; endpoint is `localhost:<port>`; any password accepted || **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` |diff --git a/ministack/services/glue.py b/ministack/services/glue.pyindex fecf4b43..68fe4e9c 100644--- a/ministack/services/glue.py+++ b/ministack/services/glue.py@@ -1453,6 +1453,40 @@ def _execute_subprocess(run, job, args, resolved):run["ErrorMessage"] = str(e)[:2000]+# Driver-side bootstrap submitted in place of the user script. The Glue 4.0+# image ships botocore 1.27, which predates AWS_ENDPOINT_URL (botocore+# 1.31.57), so the env var alone is silently ignored and a bare+# boto3.client("s3") in the script escapes to real AWS — which answers+# InvalidAccessKeyId for the emulator's credentials. Patching+# Session.create_client covers every botocore vintage; the user script then+# runs unmodified as __main__ with its own argv, so getResolvedOptions and+# __name__ checks behave identically.+_GLUE_BOOT_SCRIPT = """\+import os+import runpy+import sys++_endpoint = os.environ.get("AWS_ENDPOINT_URL")+if _endpoint:+ try:+ import botocore.session as _bs+ _orig_create_client = _bs.Session.create_client++ def _create_client(self, *args, **kwargs):+ if not kwargs.get("endpoint_url"):+ kwargs["endpoint_url"] = _endpoint+ return _orig_create_client(self, *args, **kwargs)++ _bs.Session.create_client = _create_client+ except Exception:+ pass++_script = {script!r}+sys.argv = [_script] + sys.argv[1:]+runpy.run_path(_script, run_name="__main__")+"""++def _execute_spark_docker(run, job, job_name, args, script_path, docker_client):"""Run a Glue Spark job inside an amazon/aws-glue-libs Docker container."""glue_version = job.get("GlueVersion", "4.0")@@ -1504,6 +1538,12 @@ def _execute_spark_docker(run, job, job_name, args, script_path, docker_client):"AWS_SECRET_ACCESS_KEY": os.environ.get("AWS_SECRET_ACCESS_KEY", "test"),"AWS_DEFAULT_REGION": get_region(),"AWS_REGION": get_region(),+ # Route the script's own SDK clients (boto3 et al) at MiniStack, the+ # same injection Lambda containers, CodeBuild and ECS RunTask do.+ # Only the S3A conf below covered Spark reads/writes; a bare+ # boto3.client("s3") in the script escaped to real AWS and failed+ # InvalidAccessKeyId (#1492).+ "AWS_ENDPOINT_URL": s3_endpoint,"DISABLE_SSL": "true",}@@ -1532,9 +1572,11 @@ def _execute_spark_docker(run, job, job_name, args, script_path, docker_client):if conf:cmd.extend(["--conf", conf])- # The script path inside the container+ # The script path inside the container; spark-submit is handed the+ # bootstrap, which re-runs the real script as __main__ (see+ # _GLUE_BOOT_SCRIPT).container_script = f"/tmp/{os.path.basename(script_path)}"- cmd.append(container_script)+ cmd.append("/tmp/_ministack_boot.py")# Append Glue job arguments (--key value pairs) after the scriptcmd.extend(spark_args)@@ -1562,11 +1604,14 @@ def _execute_spark_docker(run, job, job_name, args, script_path, docker_client):import ioimport tarfilescript_data = open(script_path, "rb").read()+ boot_data = _GLUE_BOOT_SCRIPT.format(script=container_script).encode()tar_buf = io.BytesIO()with tarfile.open(fileobj=tar_buf, mode="w") as tar:- info = tarfile.TarInfo(name=os.path.basename(script_path))- info.size = len(script_data)- tar.addfile(info, io.BytesIO(script_data))+ for name, data in ((os.path.basename(script_path), script_data),+ ("_ministack_boot.py", boot_data)):+ info = tarfile.TarInfo(name=name)+ info.size = len(data)+ tar.addfile(info, io.BytesIO(data))tar_buf.seek(0)container.put_archive("/tmp", tar_buf)container.start()diff --git a/ministack/services/rds.py b/ministack/services/rds.pyindex f0ea9db8..a553a087 100644--- a/ministack/services/rds.py+++ b/ministack/services/rds.py@@ -21,7 +21,13 @@ Supports: CreateDBInstance, DeleteDBInstance, DescribeDBInstances, ModifyDBInstaCreateGlobalCluster, DescribeGlobalClusters, DeleteGlobalCluster,RemoveFromGlobalCluster, ModifyGlobalCluster,SwitchoverGlobalCluster, FailoverGlobalCluster,- EnableHttpEndpoint, DisableHttpEndpoint.+ EnableHttpEndpoint, DisableHttpEndpoint,+ CreateDBProxy, DescribeDBProxies, ModifyDBProxy, DeleteDBProxy,+ CreateDBProxyEndpoint, DescribeDBProxyEndpoints,+ ModifyDBProxyEndpoint, DeleteDBProxyEndpoint,+ DescribeDBProxyTargetGroups, ModifyDBProxyTargetGroup,+ RegisterDBProxyTargets, DeregisterDBProxyTargets,+ DescribeDBProxyTargets.When Docker is available, CreateDBInstance spins up a real Postgres/MySQL containerand returns the actual host:port as the endpoint.@@ -39,6 +45,7 @@ import hashlibimport jsonimport loggingimport os+import reimport secrets as stdlib_secretsimport socketimport threading@@ -103,6 +110,8 @@ _snapshots = AccountRegionScopedDict()_db_cluster_param_groups = AccountRegionScopedDict()_db_cluster_snapshots = AccountRegionScopedDict()_option_groups = AccountRegionScopedDict()+_db_proxies = AccountRegionScopedDict()+_db_proxy_endpoints = AccountRegionScopedDict()_global_clusters = AccountScopedDict()_tags = AccountScopedDict()_port_counter = [BASE_PORT]@@ -315,6 +324,8 @@ def get_state():"db_cluster_param_groups": copy.deepcopy(_db_cluster_param_groups),"db_cluster_snapshots": copy.deepcopy(_db_cluster_snapshots),"option_groups": copy.deepcopy(_option_groups),+ "db_proxies": copy.deepcopy(_db_proxies),+ "db_proxy_endpoints": copy.deepcopy(_db_proxy_endpoints),"global_clusters": copy.deepcopy(_global_clusters),"tags": copy.deepcopy(_tags),"port_counter": _port_counter[0],@@ -362,6 +373,8 @@ def restore_state(data):_db_cluster_param_groups.update(data.get("db_cluster_param_groups", {}))_db_cluster_snapshots.update(data.get("db_cluster_snapshots", {}))_option_groups.update(data.get("option_groups", {}))+ _db_proxies.update(data.get("db_proxies", {}))+ _db_proxy_endpoints.update(data.get("db_proxy_endpoints", {}))_global_clusters.update(data.get("global_clusters", {}))# Persistence contains every account, while AccountScopedDict.values()# intentionally exposes only the active request account. Reconcile the@@ -2992,6 +3005,44 @@ def _json_key_to_query_param_name(key: str) -> str:return key+def _flatten_json_scalar(params, key, val):+ if isinstance(val, bool):+ params[key] = ["true" if val else "false"]+ elif isinstance(val, (int, float)):+ params[key] = [str(val)]+ elif isinstance(val, str):+ params[key] = [val]+ else:+ return False+ return True+++def _flatten_json_struct(params, prefix, data):+ """Flatten a nested JSON object to Query-API ``Prefix.Member`` params."""+ for key, val in data.items():+ if val is None:+ continue+ qkey = f"{prefix}.{key}"+ if _flatten_json_scalar(params, qkey, val):+ continue+ if isinstance(val, list):+ _flatten_json_list(params, qkey, val)+ elif isinstance(val, dict):+ _flatten_json_struct(params, qkey, val)+++def _flatten_json_list(params, prefix, values):+ """Flatten a JSON array to the Query-API ``Prefix.member.N`` form."""+ for i, item in enumerate(values, 1):+ base = f"{prefix}.member.{i}"+ if item is None:+ continue+ if _flatten_json_scalar(params, base, item):+ continue+ if isinstance(item, dict):+ _flatten_json_struct(params, base, item)++def _flatten_json_request_params(params, data):"""Merge SigV4 JSON (``application/x-amz-json-1.*``) bodies into query-style params.@@ -3004,13 +3055,9 @@ def _flatten_json_request_params(params, data):if val is None:continueqkey = _json_key_to_query_param_name(key)- if isinstance(val, bool):- params[qkey] = ["true" if val else "false"]- elif isinstance(val, (int, float)):- params[qkey] = [str(val)]- elif isinstance(val, str):- params[qkey] = [val]- elif isinstance(val, list) and qkey == "Filters":+ if _flatten_json_scalar(params, qkey, val):+ continue+ if isinstance(val, list) and qkey == "Filters":for i, f in enumerate(val, 1):if not isinstance(f, dict):continue@@ -3021,6 +3068,10 @@ def _flatten_json_request_params(params, data):values = f.get("Values") or f.get("values") or []for j, v in enumerate(values, 1):params[f"Filters.member.{i}.Values.member.{j}"] = [str(v)]+ elif isinstance(val, list):+ _flatten_json_list(params, qkey, val)+ elif isinstance(val, dict):+ _flatten_json_struct(params, qkey, val)def _handle_request_sync(method, path, headers, body, query_params):@@ -7608,6 +7659,1154 @@ def _default_parameters_for_family(family):return base+# ---------------------------------------------------------------------------+# RDS Proxy (control plane)+#+# Emulation scope: metadata only. Proxies, proxy endpoints, the default target+# group and its registered targets are modelled with the documented AWS shapes,+# defaults, constraints and error codes, but no connection pooling happens —+# the endpoint hostnames are synthetic and nothing listens on them. Clients+# keep connecting to the instance/cluster endpoints. This is what Terraform,+# CloudFormation and Crossplane exercise (#1488).+# ---------------------------------------------------------------------------++# Names for proxies, proxy endpoints and target groups share one constraint:+# "must begin with a letter and must contain only ASCII letters, digits, and+# hyphens; it can't end with a hyphen or contain two consecutive hyphens".+_DB_PROXY_NAME_RE = re.compile(r"^[a-zA-Z](?:-?[a-zA-Z0-9]+)*$")+_DB_PROXY_ENGINE_FAMILIES = ("MYSQL", "POSTGRESQL", "SQLSERVER")+_DB_PROXY_DEFAULT_TARGET_GROUP = "default"+# "Each AWS account ID is limited to 20 proxies."+_DB_PROXY_QUOTA = 20+# "You can add up to 20 additional proxy endpoints for each proxy."+_DB_PROXY_MAX_USER_ENDPOINTS = 20+# "Array Members: Minimum number of 0 items. Maximum number of 200 items."+_DB_PROXY_MAX_AUTH_ENTRIES = 200+# DescribeDBProxies* MaxRecords: "Default: 100 Constraints: Minimum 20,+# maximum 100."+_DB_PROXY_DEFAULT_MAX_RECORDS = 100+_DB_PROXY_MIN_MAX_RECORDS = 20+# EngineFamily -> the engines that family "supports", per the DBProxy docs:+# "MYSQL supports Aurora MySQL, RDS for MariaDB, and RDS for MySQL databases.+# POSTGRESQL supports Aurora PostgreSQL and RDS for PostgreSQL databases.+# SQLSERVER supports RDS for Microsoft SQL Server databases."+_DB_PROXY_ENGINE_FAMILY_ENGINES = {+ "MYSQL": ("mysql", "mariadb", "aurora-mysql", "aurora"),+ "POSTGRESQL": ("postgres", "aurora-postgresql"),+ "SQLSERVER": (+ "sqlserver-se", "sqlserver-ee", "sqlserver-ex", "sqlserver-web",+ ),+}+++def _new_db_proxy_id(prefix):+ return f"{prefix}-{stdlib_secrets.token_hex(9)[:17]}"+++def _invalid_parameter_value(message):+ return _error("InvalidParameterValue", message, 400)+++def _invalid_parameter_combination(message):+ return _error("InvalidParameterCombination", message, 400)+++def _db_proxy_name_error(name, label):+ if not name:+ return _error("MissingParameter", f"{label} is required", 400)+ if len(name) > 63 or not _DB_PROXY_NAME_RE.match(name):+ return _invalid_parameter_value(+ f"The parameter {label} is not a valid identifier. "+ "Identifiers must begin with a letter; must contain only ASCII "+ "letters, digits, and hyphens; and must not end with a hyphen or "+ "contain two consecutive hyphens."+ )+ return None+++def _db_proxy_enum_error(params, label, allowed):+ value = _p(params, label)+ if value and value not in allowed:+ return _invalid_parameter_value(+ f"Invalid value {value} for {label}. "+ f"Valid values are {' | '.join(allowed)}."+ )+ return None+++def _db_proxy_int_error(params, label, minimum, maximum):+ """Return (value, error). value is None when the parameter is absent."""+ raw = _p(params, label)+ if not raw:+ return None, None+ try:+ value = int(raw)+ except ValueError:+ return None, _invalid_parameter_value(+ f"Invalid value {raw} for {label}. Must be an integer."+ )+ if value < minimum or value > maximum:+ return None, _invalid_parameter_value(+ f"Invalid value {value} for {label}. "+ f"Must be between {minimum} and {maximum}."+ )+ return value, None+++def _db_proxy_not_found(name):+ return _error(+ "DBProxyNotFoundFault",+ f"The specified proxy name {name} doesn't correspond to a proxy owned "+ "by your Amazon Web Services account in the specified Amazon Web "+ "Services Region.",+ 404,+ )+++def _db_proxy_endpoint_not_found(name):+ return _error(+ "DBProxyEndpointNotFoundFault",+ f"The DB proxy endpoint {name} doesn't exist.",+ 404,+ )+++def _db_proxy_target_group_not_found(name):+ return _error(+ "DBProxyTargetGroupNotFoundFault",+ f"The specified target group {name} isn't available for a proxy owned "+ "by your Amazon Web Services account in the specified Amazon Web "+ "Services Region.",+ 404,+ )+++def _get_db_proxy(name):+ return _request_region_get(_db_proxies, name, "db-proxy")+++def _db_proxy_page(params, records, key_fn, label):+ """Apply the RDS `Marker` / `MaxRecords` contract.++ Returns ``(page, next_marker, error)``. ``next_marker`` is None when the+ page is the last one, in which case no `Marker` is emitted.+ """+ max_records, error = _db_proxy_int_error(+ params, "MaxRecords",+ _DB_PROXY_MIN_MAX_RECORDS, _DB_PROXY_DEFAULT_MAX_RECORDS,+ )+ if error:+ return None, None, error+ if max_records is None:+ max_records = _DB_PROXY_DEFAULT_MAX_RECORDS++ marker = _p(params, "Marker")+ if marker:+ keys = [key_fn(record) for record in records]+ if marker not in keys:+ return None, None, _invalid_parameter_value(+ f"Invalid value {marker} for Marker. "+ f"It does not identify a {label} in this request's results."+ )+ records = records[keys.index(marker) + 1:]++ page = records[:max_records]+ next_marker = key_fn(page[-1]) if len(records) > max_records else None+ return page, next_marker, None+++def _marker_xml(next_marker):+ return f"<Marker>{_esc(next_marker)}</Marker>" if next_marker else ""+++def _parse_user_auth_configs(params, prefix="Auth"):+ """Parse Auth.member.N.<field> (Query API) into UserAuthConfig dicts."""+ fields = (+ "Description",+ "UserName",+ "AuthScheme",+ "SecretArn",+ "IAMAuth",+ "ClientPasswordAuthType",+ )+ configs = []+ i = 1+ while True:+ base = f"{prefix}.member.{i}"+ if not any(_p(params, f"{base}.{field}") for field in fields):+ break+ entry = {}+ for field in fields:+ value = _p(params, f"{base}.{field}")+ if value:+ entry[field] = value+ configs.append(entry)+ i += 1+ return configs+++def _db_proxy_auth_error(auth):+ if len(auth) > _DB_PROXY_MAX_AUTH_ENTRIES:+ return _invalid_parameter_value(+ f"Invalid number of Auth entries: {len(auth)}. "+ f"A proxy supports at most {_DB_PROXY_MAX_AUTH_ENTRIES}."+ )+ for entry in auth:+ scheme = entry.get("AuthScheme")+ if scheme and scheme != "SECRETS":+ return _invalid_parameter_value(+ f"Invalid value {scheme} for AuthScheme. "+ "Valid values are SECRETS."+ )+ iam_auth = entry.get("IAMAuth")+ if iam_auth and iam_auth not in ("DISABLED", "REQUIRED", "ENABLED"):+ return _invalid_parameter_value(+ f"Invalid value {iam_auth} for IAMAuth. "+ "Valid values are DISABLED | REQUIRED | ENABLED."+ )+ return None+++def _default_connection_pool_config(engine_family):+ # "Default: 10 for RDS for Microsoft SQL Server, and 100 for all other+ # engines" / "If the value of MaxConnectionsPercent isn't specified, then+ # for SQL Server, MaxIdleConnectionsPercent is 5, and for all other+ # engines, the default is 50" / "Default: 120".+ sqlserver = engine_family == "SQLSERVER"+ return {+ "MaxConnectionsPercent": 10 if sqlserver else 100,+ "MaxIdleConnectionsPercent": 5 if sqlserver else 50,+ "ConnectionBorrowTimeout": 120,+ "SessionPinningFilters": [],+ }+++def _create_db_proxy(p):+ name = _p(p, "DBProxyName")+ name_error = _db_proxy_name_error(name, "DBProxyName")+ if name_error:+ return name_error++ engine_family = _p(p, "EngineFamily")+ if not engine_family:+ return _error("MissingParameter", "EngineFamily is required", 400)+ if engine_family not in _DB_PROXY_ENGINE_FAMILIES:+ return _invalid_parameter_value(+ f"Invalid value {engine_family} for EngineFamily. "+ f"Valid values are {' | '.join(_DB_PROXY_ENGINE_FAMILIES)}."+ )++ role_arn = _p(p, "RoleArn")+ if not role_arn:+ return _error("MissingParameter", "RoleArn is required", 400)+ if not 20 <= len(role_arn) <= 2048:+ return _invalid_parameter_value(+ "Invalid value for RoleArn. Must be between 20 and 2048 "+ "characters."+ )++ subnet_ids = _parse_member_list(p, "VpcSubnetIds")+ if not subnet_ids:+ return _error("MissingParameter", "VpcSubnetIds is required", 400)++ for label, allowed in (+ ("DefaultAuthScheme", ("IAM_AUTH", "NONE")),+ ("EndpointNetworkType", ("IPV4", "IPV6", "DUAL")),+ ("TargetConnectionNetworkType", ("IPV4", "IPV6")),+ ):+ enum_error = _db_proxy_enum_error(p, label, allowed)+ if enum_error:+ return enum_error++ idle_timeout, error = _db_proxy_int_error(p, "IdleClientTimeout", 1, 28800)+ if error:+ return error++ auth = _parse_user_auth_configs(p)+ auth_error = _db_proxy_auth_error(auth)+ if auth_error:+ return auth_error+ default_auth_scheme = _p(p, "DefaultAuthScheme")+ # "If you don't specify DefaultAuthScheme or specify this parameter as+ # NONE, you must specify the Auth option."+ if default_auth_scheme in ("", "NONE") and not auth:+ return _invalid_parameter_combination(+ "Auth is required when DefaultAuthScheme is not specified or is "+ "NONE."+ )++ if _db_proxies.get(name):+ return _error(+ "DBProxyAlreadyExistsFault",+ f"The specified proxy name {name} must be unique for all proxies "+ "owned by your Amazon Web Services account in the specified "+ "Amazon Web Services Region.",+ 400,+ )+ if len(_db_proxies.values()) >= _DB_PROXY_QUOTA:+ return _error(+ "DBProxyQuotaExceededFault",+ "Your Amazon Web Services account already has the maximum number "+ "of proxies in the specified Amazon Web Services Region.",+ 400,+ )++ resolved = _resolve_subnet_group_members(subnet_ids)+ if resolved is None:+ return _error("InvalidSubnet", _INVALID_SUBNET_MESSAGE, 400)+ _subnets, vpc_id = resolved++ region = get_region()+ account_id = get_account_id()+ proxy_id = _new_db_proxy_id("prx")+ arn = f"arn:aws:rds:{region}:{account_id}:db-proxy:{proxy_id}"+ # Real endpoints read "the-proxy.proxy-demo.us-east-1.rds.amazonaws.com" —+ # the middle label is an account/region-scoped hash we can only synthesize.+ endpoint_suffix = new_uuid()[:8]+ now = time.time()++ proxy = {+ "DBProxyName": name,+ "DBProxyArn": arn,+ "Status": "available",+ "EngineFamily": engine_family,+ "VpcId": vpc_id,+ "VpcSecurityGroupIds": _parse_member_list(p, "VpcSecurityGroupIds"),+ "VpcSubnetIds": subnet_ids,+ "Auth": auth,+ "RoleArn": role_arn,+ "Endpoint": f"{name}.proxy-{endpoint_suffix}.{region}.rds.amazonaws.com",+ "RequireTLS": _p(p, "RequireTLS") == "true",+ # "Default: 1800 (30 minutes) Constraints: 1 to 28,800"+ "IdleClientTimeout": idle_timeout if idle_timeout is not None else 1800,+ "DebugLogging": _p(p, "DebugLogging") == "true",+ "CreatedDate": now,+ "UpdatedDate": now,+ # "Default: IPV4" for both network-type parameters.+ "EndpointNetworkType": _p(p, "EndpointNetworkType") or "IPV4",+ "TargetConnectionNetworkType": _p(p, "TargetConnectionNetworkType") or "IPV4",+ "_EndpointSuffix": endpoint_suffix,+ "TargetGroup": {+ "DBProxyName": name,+ "TargetGroupName": _DB_PROXY_DEFAULT_TARGET_GROUP,+ "TargetGroupArn": (+ f"arn:aws:rds:{region}:{account_id}:target-group:"+ f"{_new_db_proxy_id('prx-tg')}"+ ),+ "IsDefault": True,+ "Status": "available",+ "ConnectionPoolConfig": _default_connection_pool_config(engine_family),+ "CreatedDate": now,+ "UpdatedDate": now,+ },+ "Targets": [],+ }+ if default_auth_scheme:+ proxy["DefaultAuthScheme"] = default_auth_scheme+ _db_proxies[name] = proxy++ # "RDS automatically creates one endpoint for each DB proxy." Default+ # endpoints always have read/write capability.+ _db_proxy_endpoints[name] = {+ "DBProxyEndpointName": name,+ "DBProxyEndpointArn": (+ f"arn:aws:rds:{region}:{account_id}:db-proxy-endpoint:"+ f"{_new_db_proxy_id('prx-endpoint')}"+ ),+ "DBProxyName": name,+ "Status": "available",+ "VpcId": vpc_id,+ "VpcSecurityGroupIds": list(proxy["VpcSecurityGroupIds"]),+ "VpcSubnetIds": list(subnet_ids),+ "Endpoint": proxy["Endpoint"],+ "CreatedDate": now,+ "TargetRole": "READ_WRITE",+ "IsDefault": True,+ "EndpointNetworkType": proxy["EndpointNetworkType"],+ }++ req_tags = _parse_tags(p)+ if req_tags:+ _tags[arn] = req_tags++ return _xml(200, "CreateDBProxyResponse",+ f"<CreateDBProxyResult><DBProxy>{_db_proxy_xml(proxy)}</DBProxy></CreateDBProxyResult>")+++def _describe_db_proxies(p):+ name = _p(p, "DBProxyName")+ if name:+ proxy = _get_db_proxy(name)+ if not proxy:+ return _db_proxy_not_found(name)+ proxies = [proxy]+ else:+ proxies = sorted(+ _db_proxies.values(), key=lambda px: px["DBProxyName"],+ )++ page, next_marker, error = _db_proxy_page(+ p, proxies, lambda px: px["DBProxyName"], "DB proxy",+ )+ if error:+ return error++ members = "".join(f"<member>{_db_proxy_xml(px)}</member>" for px in page)+ return _xml(200, "DescribeDBProxiesResponse",+ f"<DescribeDBProxiesResult><DBProxies>{members}</DBProxies>"+ f"{_marker_xml(next_marker)}</DescribeDBProxiesResult>")+++def _modify_db_proxy(p):+ name = _p(p, "DBProxyName")+ proxy = _get_db_proxy(name)+ if not proxy:+ return _db_proxy_not_found(name)++ new_name = _p(p, "NewDBProxyName")+ if new_name and new_name != name:+ name_error = _db_proxy_name_error(new_name, "NewDBProxyName")+ if name_error:+ return name_error+ if _db_proxies.get(new_name):+ return _error(+ "DBProxyAlreadyExistsFault",+ f"The specified proxy name {new_name} must be unique for all "+ "proxies owned by your Amazon Web Services account in the "+ "specified Amazon Web Services Region.",+ 400,+ )++ enum_error = _db_proxy_enum_error(+ p, "DefaultAuthScheme", ("IAM_AUTH", "NONE"),+ )+ if enum_error:+ return enum_error++ idle_timeout, error = _db_proxy_int_error(p, "IdleClientTimeout", 1, 28800)+ if error:+ return error++ role_arn = _p(p, "RoleArn")+ if role_arn and not 20 <= len(role_arn) <= 2048:+ return _invalid_parameter_value(+ "Invalid value for RoleArn. Must be between 20 and 2048 "+ "characters."+ )++ auth = _parse_user_auth_configs(p)+ auth_error = _db_proxy_auth_error(auth)+ if auth_error:+ return auth_error+ default_auth_scheme = _p(p, "DefaultAuthScheme")+ effective_auth = auth or proxy["Auth"]+ effective_scheme = default_auth_scheme or proxy.get("DefaultAuthScheme", "")+ if effective_scheme in ("", "NONE") and not effective_auth:+ return _invalid_parameter_combination(+ "Auth is required when DefaultAuthScheme is not specified or is "+ "NONE."+ )++ if "RequireTLS" in p:+ proxy["RequireTLS"] = _p(p, "RequireTLS") == "true"+ if "DebugLogging" in p:+ proxy["DebugLogging"] = _p(p, "DebugLogging") == "true"+ if idle_timeout is not None:+ proxy["IdleClientTimeout"] = idle_timeout+ if role_arn:+ proxy["RoleArn"] = role_arn+ if default_auth_scheme:+ proxy["DefaultAuthScheme"] = default_auth_scheme+ if auth:+ proxy["Auth"] = auth+ security_groups = _parse_member_list(p, "SecurityGroups")+ if security_groups:+ proxy["VpcSecurityGroupIds"] = security_groups++ if new_name and new_name != name:+ region = get_region()+ proxy["DBProxyName"] = new_name+ proxy["Endpoint"] = (+ f"{new_name}.proxy-{proxy['_EndpointSuffix']}.{region}.rds.amazonaws.com"+ )+ proxy["TargetGroup"]["DBProxyName"] = new_name+ for endpoint in list(_db_proxy_endpoints.values()):+ if endpoint["DBProxyName"] != name:+ continue+ endpoint["DBProxyName"] = new_name+ if endpoint.get("IsDefault"):+ endpoint["DBProxyEndpointName"] = new_name+ endpoint["Endpoint"] = proxy["Endpoint"]+ _db_proxy_endpoints.pop(name, None)+ _db_proxy_endpoints[new_name] = endpoint+ _db_proxies.pop(name, None)+ _db_proxies[new_name] = proxy++ proxy["UpdatedDate"] = time.time()+ return _xml(200, "ModifyDBProxyResponse",+ f"<ModifyDBProxyResult><DBProxy>{_db_proxy_xml(proxy)}</DBProxy></ModifyDBProxyResult>")+++def _delete_db_proxy(p):+ name = _p(p, "DBProxyName")+ proxy = _get_db_proxy(name)+ if not proxy:+ return _db_proxy_not_found(name)++ proxy_name = proxy["DBProxyName"]+ for endpoint_name, endpoint in list(_db_proxy_endpoints.items()):+ if endpoint["DBProxyName"] == proxy_name:+ _tags.pop(endpoint.get("DBProxyEndpointArn", ""), None)+ _db_proxy_endpoints.pop(endpoint_name, None)+ _db_proxies.pop(proxy_name, None)+ _tags.pop(proxy.get("DBProxyArn", ""), None)++ proxy["Status"] = "deleting"+ return _xml(200, "DeleteDBProxyResponse",+ f"<DeleteDBProxyResult><DBProxy>{_db_proxy_xml(proxy)}</DBProxy></DeleteDBProxyResult>")+++def _create_db_proxy_endpoint(p):+ proxy_name = _p(p, "DBProxyName")+ proxy = _get_db_proxy(proxy_name)+ if not proxy:+ return _db_proxy_not_found(proxy_name)++ endpoint_name = _p(p, "DBProxyEndpointName")+ name_error = _db_proxy_name_error(endpoint_name, "DBProxyEndpointName")+ if name_error:+ return name_error++ for label, allowed in (+ ("TargetRole", ("READ_WRITE", "READ_ONLY")),+ ("EndpointNetworkType", ("IPV4", "IPV6", "DUAL")),+ ):+ enum_error = _db_proxy_enum_error(p, label, allowed)+ if enum_error:+ return enum_error++ target_role = _p(p, "TargetRole") or "READ_WRITE"+ # "The only role that proxies for RDS for Microsoft SQL Server support is+ # READ_WRITE."+ if proxy["EngineFamily"] == "SQLSERVER" and target_role != "READ_WRITE":+ return _invalid_parameter_value(+ f"Invalid value {target_role} for TargetRole. The only role that "+ "proxies for RDS for Microsoft SQL Server support is READ_WRITE."+ )++ if _db_proxy_endpoints.get(endpoint_name):+ return _error(+ "DBProxyEndpointAlreadyExistsFault",+ f"The specified DB proxy endpoint name {endpoint_name} must be "+ "unique for all DB proxy endpoints owned by your Amazon Web "+ "Services account in the specified Amazon Web Services Region.",+ 400,+ )++ user_defined = [+ endpoint+ for endpoint in _db_proxy_endpoints.values()+ if endpoint["DBProxyName"] == proxy["DBProxyName"]+ and not endpoint.get("IsDefault")+ ]+ if len(user_defined) >= _DB_PROXY_MAX_USER_ENDPOINTS:+ return _error(+ "DBProxyEndpointQuotaExceededFault",+ "The DB proxy already has the maximum number of endpoints.",+ 400,+ )++ subnet_ids = _parse_member_list(p, "VpcSubnetIds")+ if not subnet_ids:+ return _error("MissingParameter", "VpcSubnetIds is required", 400)+ resolved = _resolve_subnet_group_members(subnet_ids)+ if resolved is None:+ return _error("InvalidSubnet", _INVALID_SUBNET_MESSAGE, 400)+ _subnets, vpc_id = resolved++ region = get_region()+ security_groups = _parse_member_list(p, "VpcSecurityGroupIds")+ endpoint = {+ "DBProxyEndpointName": endpoint_name,+ "DBProxyEndpointArn": (+ f"arn:aws:rds:{region}:{get_account_id()}:db-proxy-endpoint:"+ f"{_new_db_proxy_id('prx-endpoint')}"+ ),+ "DBProxyName": proxy["DBProxyName"],+ "Status": "available",+ "VpcId": vpc_id,+ "VpcSecurityGroupIds": security_groups or list(proxy["VpcSecurityGroupIds"]),+ "VpcSubnetIds": subnet_ids,+ "Endpoint": (+ f"{endpoint_name}.endpoint.proxy-{proxy['_EndpointSuffix']}"+ f".{region}.rds.amazonaws.com"+ ),+ "CreatedDate": time.time(),+ # "The default is READ_WRITE."+ "TargetRole": target_role,+ "IsDefault": False,+ "EndpointNetworkType": _p(p, "EndpointNetworkType") or "IPV4",+ }+ _db_proxy_endpoints[endpoint_name] = endpoint++ req_tags = _parse_tags(p)+ if req_tags:+ _tags[endpoint["DBProxyEndpointArn"]] = req_tags++ return _xml(200, "CreateDBProxyEndpointResponse",+ "<CreateDBProxyEndpointResult><DBProxyEndpoint>"+ f"{_db_proxy_endpoint_xml(endpoint)}"+ "</DBProxyEndpoint></CreateDBProxyEndpointResult>")+++def _describe_db_proxy_endpoints(p):+ proxy_name = _p(p, "DBProxyName")+ if proxy_name:+ proxy = _get_db_proxy(proxy_name)+ if not proxy:+ return _db_proxy_not_found(proxy_name)+ proxy_name = proxy["DBProxyName"]++ endpoint_name = _p(p, "DBProxyEndpointName")+ if endpoint_name:+ endpoint = _request_region_get(+ _db_proxy_endpoints, endpoint_name, "db-proxy-endpoint",+ )+ if not endpoint or (proxy_name and endpoint["DBProxyName"] != proxy_name):+ return _db_proxy_endpoint_not_found(endpoint_name)+ endpoints = [endpoint]+ else:+ endpoints = sorted(+ (+ endpoint+ for endpoint in _db_proxy_endpoints.values()+ if not proxy_name or endpoint["DBProxyName"] == proxy_name+ ),+ key=lambda e: e["DBProxyEndpointName"],+ )++ page, next_marker, error = _db_proxy_page(+ p, endpoints, lambda e: e["DBProxyEndpointName"], "DB proxy endpoint",+ )+ if error:+ return error++ members = "".join(+ f"<member>{_db_proxy_endpoint_xml(e)}</member>" for e in page+ )+ return _xml(200, "DescribeDBProxyEndpointsResponse",+ "<DescribeDBProxyEndpointsResult><DBProxyEndpoints>"+ f"{members}</DBProxyEndpoints>{_marker_xml(next_marker)}"+ "</DescribeDBProxyEndpointsResult>")+++def _modify_db_proxy_endpoint(p):+ endpoint_name = _p(p, "DBProxyEndpointName")+ endpoint = _request_region_get(+ _db_proxy_endpoints, endpoint_name, "db-proxy-endpoint",+ )+ if not endpoint:+ return _db_proxy_endpoint_not_found(endpoint_name)+ if endpoint.get("IsDefault"):+ # "The RDS proxy default endpoint cannot be modified."+ return _error(+ "InvalidDBProxyEndpointStateFault",+ f"The DB proxy endpoint {endpoint_name} is the default endpoint "+ "for its DB proxy and can't be modified.",+ 400,+ )++ endpoint_name = endpoint["DBProxyEndpointName"]+ new_name = _p(p, "NewDBProxyEndpointName")+ if new_name and new_name != endpoint_name:+ name_error = _db_proxy_name_error(new_name, "NewDBProxyEndpointName")+ if name_error:+ return name_error+ if _db_proxy_endpoints.get(new_name):+ return _error(+ "DBProxyEndpointAlreadyExistsFault",+ f"The specified DB proxy endpoint name {new_name} must be "+ "unique for all DB proxy endpoints owned by your Amazon Web "+ "Services account in the specified Amazon Web Services Region.",+ 400,+ )++ security_groups = _parse_member_list(p, "VpcSecurityGroupIds")+ if security_groups:+ endpoint["VpcSecurityGroupIds"] = security_groups++ if new_name and new_name != endpoint_name:+ proxy = _db_proxies.get(endpoint["DBProxyName"])+ suffix = proxy["_EndpointSuffix"] if proxy else new_uuid()[:8]+ endpoint["DBProxyEndpointName"] = new_name+ endpoint["Endpoint"] = (+ f"{new_name}.endpoint.proxy-{suffix}.{get_region()}.rds.amazonaws.com"+ )+ _db_proxy_endpoints.pop(endpoint_name, None)+ _db_proxy_endpoints[new_name] = endpoint++ return _xml(200, "ModifyDBProxyEndpointResponse",+ "<ModifyDBProxyEndpointResult><DBProxyEndpoint>"+ f"{_db_proxy_endpoint_xml(endpoint)}"+ "</DBProxyEndpoint></ModifyDBProxyEndpointResult>")+++def _delete_db_proxy_endpoint(p):+ endpoint_name = _p(p, "DBProxyEndpointName")+ endpoint = _request_region_get(+ _db_proxy_endpoints, endpoint_name, "db-proxy-endpoint",+ )+ if not endpoint:+ return _db_proxy_endpoint_not_found(endpoint_name)+ if endpoint.get("IsDefault"):+ return _error(+ "InvalidDBProxyEndpointStateFault",+ f"The DB proxy endpoint {endpoint_name} is the default endpoint "+ "for its DB proxy and can't be deleted.",+ 400,+ )++ _db_proxy_endpoints.pop(endpoint["DBProxyEndpointName"], None)+ _tags.pop(endpoint.get("DBProxyEndpointArn", ""), None)+ endpoint["Status"] = "deleting"+ return _xml(200, "DeleteDBProxyEndpointResponse",+ "<DeleteDBProxyEndpointResult><DBProxyEndpoint>"+ f"{_db_proxy_endpoint_xml(endpoint)}"+ "</DBProxyEndpoint></DeleteDBProxyEndpointResult>")+++def _resolve_db_proxy_target_group(p):+ """Return (proxy, error). The only target group AWS exposes is 'default'."""+ proxy_name = _p(p, "DBProxyName")+ proxy = _get_db_proxy(proxy_name)+ if not proxy:+ return None, _db_proxy_not_found(proxy_name)+ group_name = _p(p, "TargetGroupName")+ if group_name and group_name != _DB_PROXY_DEFAULT_TARGET_GROUP:+ return None, _db_proxy_target_group_not_found(group_name)+ return proxy, None+++def _describe_db_proxy_target_groups(p):+ proxy, error = _resolve_db_proxy_target_group(p)+ if error:+ return error++ page, next_marker, error = _db_proxy_page(+ p, [proxy["TargetGroup"]], lambda tg: tg["TargetGroupName"],+ "target group",+ )+ if error:+ return error++ members = "".join(+ f"<member>{_db_proxy_target_group_xml(tg)}</member>" for tg in page+ )+ return _xml(200, "DescribeDBProxyTargetGroupsResponse",+ f"<DescribeDBProxyTargetGroupsResult><TargetGroups>{members}"+ f"</TargetGroups>{_marker_xml(next_marker)}"+ "</DescribeDBProxyTargetGroupsResult>")+++def _modify_db_proxy_target_group(p):+ proxy, error = _resolve_db_proxy_target_group(p)+ if error:+ return error+ if not _p(p, "TargetGroupName"):+ return _error("MissingParameter", "TargetGroupName is required", 400)++ new_name = _p(p, "NewName")+ if new_name and new_name != _DB_PROXY_DEFAULT_TARGET_GROUP:+ # "You can't rename the default target group."+ return _invalid_parameter_value(+ "You can't rename the default target group."+ )++ group = proxy["TargetGroup"]+ supplied = [+ key for key in p if key.startswith("ConnectionPoolConfig.")+ ]+ if supplied:+ config, config_error = _build_connection_pool_config(+ p, proxy["EngineFamily"],+ )+ if config_error:+ return config_error+ group["ConnectionPoolConfig"] = config+ group["UpdatedDate"] = time.time()++ return _xml(200, "ModifyDBProxyTargetGroupResponse",+ "<ModifyDBProxyTargetGroupResult><DBProxyTargetGroup>"+ f"{_db_proxy_target_group_xml(group)}"+ "</DBProxyTargetGroup></ModifyDBProxyTargetGroupResult>")+++def _build_connection_pool_config(p, engine_family):+ """Build a ConnectionPoolConfig from a request, applying AWS's defaults.++ AWS documents each field's default in terms of what the *call* specifies+ ("If the value of MaxConnectionsPercent isn't specified, then ... the+ default is 50"), so a supplied ConnectionPoolConfig replaces the stored+ one rather than merging into it.+ """+ max_connections, error = _db_proxy_int_error(+ p, "ConnectionPoolConfig.MaxConnectionsPercent", 1, 100,+ )+ if error:+ return None, error+ max_idle, error = _db_proxy_int_error(+ p, "ConnectionPoolConfig.MaxIdleConnectionsPercent", 0, 100,+ )+ if error:+ return None, error+ borrow_timeout, error = _db_proxy_int_error(+ p, "ConnectionPoolConfig.ConnectionBorrowTimeout", 0, 300,+ )+ if error:+ return None, error++ # "If you specify MaxIdleConnectionsPercent, then you must also include a+ # value for MaxConnectionsPercent."+ if max_idle is not None and max_connections is None:+ return None, _invalid_parameter_combination(+ "MaxConnectionsPercent must be specified when "+ "MaxIdleConnectionsPercent is specified."+ )++ defaults = _default_connection_pool_config(engine_family)+ if max_connections is None:+ max_connections = defaults["MaxConnectionsPercent"]+ if max_idle is None:+ max_idle = defaults["MaxIdleConnectionsPercent"]+ elif max_idle is None:+ # "The default value is half of the value of MaxConnectionsPercent."+ max_idle = max_connections // 2++ # "Must be between 0 and the value of MaxConnectionsPercent."+ if max_idle > max_connections:+ return None, _invalid_parameter_value(+ f"Invalid value {max_idle} for MaxIdleConnectionsPercent. "+ f"Must be between 0 and the value of MaxConnectionsPercent "+ f"({max_connections})."+ )++ config = {+ "MaxConnectionsPercent": max_connections,+ "MaxIdleConnectionsPercent": max_idle,+ "ConnectionBorrowTimeout": (+ borrow_timeout if borrow_timeout is not None+ else defaults["ConnectionBorrowTimeout"]+ ),+ "SessionPinningFilters": _parse_member_list(+ p, "ConnectionPoolConfig.SessionPinningFilters",+ ),+ }+ init_query = _p(p, "ConnectionPoolConfig.InitQuery")+ if init_query:+ config["InitQuery"] = init_query+ return config, None+++def _db_proxy_engine_family_error(proxy, engine, identifier):+ """Refuse a target whose engine the proxy's EngineFamily doesn't support."""+ family = proxy["EngineFamily"]+ supported = _DB_PROXY_ENGINE_FAMILY_ENGINES.get(family, ())+ if engine and engine not in supported:+ return _invalid_parameter_value(+ f"The engine {engine} of {identifier} is not supported by a proxy "+ f"with an EngineFamily of {family}."+ )+ return None+++def _register_db_proxy_targets(p):+ proxy, error = _resolve_db_proxy_target_group(p)+ if error:+ return error++ instance_ids = _parse_member_list(p, "DBInstanceIdentifiers")+ cluster_ids = _parse_member_list(p, "DBClusterIdentifiers")+ registered = {+ (target["Type"], target["RdsResourceId"]) for target in proxy["Targets"]+ }++ new_targets = []+ for instance_id in instance_ids:+ instance = _instances.get(instance_id)+ if not instance:+ return _error(+ "DBInstanceNotFound",+ f"DBInstance {instance_id} not found.",+ 404,+ )+ if ("RDS_INSTANCE", instance_id) in registered:+ return _error(+ "DBProxyTargetAlreadyRegisteredFault",+ "The proxy is already associated with the specified RDS DB "+ f"instance {instance_id}.",+ 400,+ )+ family_error = _db_proxy_engine_family_error(+ proxy, instance.get("Engine", ""), instance_id,+ )+ if family_error:+ return family_error+ new_targets.append({+ "RdsResourceId": instance_id,+ "Type": "RDS_INSTANCE",+ "Role": "READ_WRITE",+ })++ for cluster_id in cluster_ids:+ cluster = _clusters.get(cluster_id)+ if not cluster:+ return _error(+ "DBClusterNotFoundFault",+ f"DBCluster {cluster_id} not found.",+ 404,+ )+ if ("TRACKED_CLUSTER", cluster_id) in registered:+ return _error(+ "DBProxyTargetAlreadyRegisteredFault",+ "The proxy is already associated with the specified Aurora DB "+ f"cluster {cluster_id}.",+ 400,+ )+ family_error = _db_proxy_engine_family_error(+ proxy, cluster.get("Engine", ""), cluster_id,+ )+ if family_error:+ return family_error+ new_targets.append({+ "TrackedClusterId": cluster_id,+ "RdsResourceId": cluster_id,+ "Type": "TRACKED_CLUSTER",+ "Role": "READ_WRITE",+ })++ # "Each proxy can be associated with a single target DB instance. However,+ # you can associate multiple proxies with the same DB instance."+ if len(proxy["Targets"]) + len(new_targets) > 1:+ return _invalid_parameter_value(+ f"The proxy {proxy['DBProxyName']} can be associated with a "+ "single target. Deregister the current target before registering "+ "another one."+ )++ proxy["Targets"].extend(new_targets)+ members = "".join(+ f"<member>{_db_proxy_target_xml(_db_proxy_target_view(t))}</member>"+ for t in new_targets+ )+ return _xml(200, "RegisterDBProxyTargetsResponse",+ "<RegisterDBProxyTargetsResult><DBProxyTargets>"+ f"{members}"+ "</DBProxyTargets></RegisterDBProxyTargetsResult>")+++def _db_proxy_target_view(target):+ """Resolve a registration against the live instance/cluster record.++ Endpoint, port and health are read at describe time, not frozen at+ registration: a target whose backing database was deleted or stopped must+ not keep reporting itself AVAILABLE at the address it used to have.+ """+ view = dict(target)+ identifier = target["RdsResourceId"]+ if target["Type"] == "RDS_INSTANCE":+ record = _instances.get(identifier)+ arn_key, status_key = "DBInstanceArn", "DBInstanceStatus"+ endpoint = (record or {}).get("Endpoint", {})+ address, port = endpoint.get("Address", ""), endpoint.get("Port", 0)+ else:+ record = _clusters.get(identifier)+ arn_key, status_key = "DBClusterArn", "Status"+ address = (record or {}).get("Endpoint", "")+ port = (record or {}).get("Port", 0)++ if record is None:+ view["TargetArn"] = ""+ view["Endpoint"] = ""+ view["Port"] = 0+ view["TargetHealth"] = {"State": "UNAVAILABLE"}+ return view++ view["TargetArn"] = record.get(arn_key, "")+ view["Endpoint"] = address+ view["Port"] = port+ stopped = record.get(status_key) == "stopped"+ view["TargetHealth"] = {"State": "UNAVAILABLE" if stopped else "AVAILABLE"}+ return view+++def _deregister_db_proxy_targets(p):+ proxy, error = _resolve_db_proxy_target_group(p)+ if error:+ return error++ wanted = [+ ("RDS_INSTANCE", identifier)+ for identifier in _parse_member_list(p, "DBInstanceIdentifiers")+ ] + [+ ("TRACKED_CLUSTER", identifier)+ for identifier in _parse_member_list(p, "DBClusterIdentifiers")+ ]+ registered = {+ (target["Type"], target["RdsResourceId"]) for target in proxy["Targets"]+ }+ for target_type, identifier in wanted:+ if (target_type, identifier) not in registered:+ return _error(+ "DBProxyTargetNotFoundFault",+ "The specified RDS DB instance or Aurora DB cluster "+ f"{identifier} isn't available for a proxy owned by your "+ "Amazon Web Services account in the specified Amazon Web "+ "Services Region.",+ 404,+ )++ drop = set(wanted)+ proxy["Targets"] = [+ target+ for target in proxy["Targets"]+ if (target["Type"], target["RdsResourceId"]) not in drop+ ]+ # DeregisterDBProxyTargets has an empty output shape, so botocore still+ # looks for the wrapping result element.+ return _xml(200, "DeregisterDBProxyTargetsResponse",+ "<DeregisterDBProxyTargetsResult/>")+++def _describe_db_proxy_targets(p):+ proxy, error = _resolve_db_proxy_target_group(p)+ if error:+ return error++ page, next_marker, error = _db_proxy_page(+ p, proxy["Targets"],+ lambda t: f"{t['Type']}:{t['RdsResourceId']}", "target",+ )+ if error:+ return error++ members = "".join(+ f"<member>{_db_proxy_target_xml(_db_proxy_target_view(t))}</member>"+ for t in page+ )+ return _xml(200, "DescribeDBProxyTargetsResponse",+ f"<DescribeDBProxyTargetsResult><Targets>{members}</Targets>"+ f"{_marker_xml(next_marker)}</DescribeDBProxyTargetsResult>")+++def _string_list_xml(tag, values):+ members = "".join(f"<member>{_esc(v)}</member>" for v in values)+ return f"<{tag}>{members}</{tag}>"+++def _db_proxy_xml(px):+ auth_xml = ""+ for entry in px.get("Auth", []):+ fields = "".join(+ f"<{field}>{_esc(entry[field])}</{field}>"+ for field in (+ "Description",+ "UserName",+ "AuthScheme",+ "SecretArn",+ "IAMAuth",+ "ClientPasswordAuthType",+ )+ if entry.get(field)+ )+ auth_xml += f"<member>{fields}</member>"+ default_auth_scheme = px.get("DefaultAuthScheme")+ default_auth_xml = (+ f"<DefaultAuthScheme>{_esc(default_auth_scheme)}</DefaultAuthScheme>"+ if default_auth_scheme+ else ""+ )+ return f"""<DBProxyName>{_esc(px['DBProxyName'])}</DBProxyName>+ <DBProxyArn>{px['DBProxyArn']}</DBProxyArn>+ <Status>{px['Status']}</Status>+ <EngineFamily>{px['EngineFamily']}</EngineFamily>+ <VpcId>{px.get('VpcId','')}</VpcId>+ {_string_list_xml('VpcSecurityGroupIds', px.get('VpcSecurityGroupIds', []))}+ {_string_list_xml('VpcSubnetIds', px.get('VpcSubnetIds', []))}+ {default_auth_xml}+ <Auth>{auth_xml}</Auth>+ <RoleArn>{_esc(px.get('RoleArn',''))}</RoleArn>+ <Endpoint>{px.get('Endpoint','')}</Endpoint>+ <RequireTLS>{str(px.get('RequireTLS', False)).lower()}</RequireTLS>+ <IdleClientTimeout>{px.get('IdleClientTimeout', 1800)}</IdleClientTimeout>+ <DebugLogging>{str(px.get('DebugLogging', False)).lower()}</DebugLogging>+ <CreatedDate>{_format_time(px['CreatedDate'])}</CreatedDate>+ <UpdatedDate>{_format_time(px['UpdatedDate'])}</UpdatedDate>+ <EndpointNetworkType>{px.get('EndpointNetworkType','IPV4')}</EndpointNetworkType>+ <TargetConnectionNetworkType>{px.get('TargetConnectionNetworkType','IPV4')}</TargetConnectionNetworkType>"""+++def _db_proxy_endpoint_xml(ep):+ return f"""<DBProxyEndpointName>{_esc(ep['DBProxyEndpointName'])}</DBProxyEndpointName>+ <DBProxyEndpointArn>{ep['DBProxyEndpointArn']}</DBProxyEndpointArn>+ <DBProxyName>{_esc(ep['DBProxyName'])}</DBProxyName>+ <Status>{ep['Status']}</Status>+ <VpcId>{ep.get('VpcId','')}</VpcId>+ {_string_list_xml('VpcSecurityGroupIds', ep.get('VpcSecurityGroupIds', []))}+ {_string_list_xml('VpcSubnetIds', ep.get('VpcSubnetIds', []))}+ <Endpoint>{ep.get('Endpoint','')}</Endpoint>+ <CreatedDate>{_format_time(ep['CreatedDate'])}</CreatedDate>+ <TargetRole>{ep.get('TargetRole','READ_WRITE')}</TargetRole>+ <IsDefault>{str(ep.get('IsDefault', False)).lower()}</IsDefault>+ <EndpointNetworkType>{ep.get('EndpointNetworkType','IPV4')}</EndpointNetworkType>"""+++def _db_proxy_target_group_xml(tg):+ config = tg.get("ConnectionPoolConfig", {})+ init_query = config.get("InitQuery")+ init_query_xml = (+ f"<InitQuery>{_esc(init_query)}</InitQuery>" if init_query else ""+ )+ return f"""<DBProxyName>{_esc(tg['DBProxyName'])}</DBProxyName>+ <TargetGroupName>{_esc(tg['TargetGroupName'])}</TargetGroupName>+ <TargetGroupArn>{tg['TargetGroupArn']}</TargetGroupArn>+ <IsDefault>{str(tg.get('IsDefault', True)).lower()}</IsDefault>+ <Status>{tg.get('Status','available')}</Status>+ <ConnectionPoolConfig>+ <MaxConnectionsPercent>{config.get('MaxConnectionsPercent', 100)}</MaxConnectionsPercent>+ <MaxIdleConnectionsPercent>{config.get('MaxIdleConnectionsPercent', 50)}</MaxIdleConnectionsPercent>+ <ConnectionBorrowTimeout>{config.get('ConnectionBorrowTimeout', 120)}</ConnectionBorrowTimeout>+ {_string_list_xml('SessionPinningFilters', config.get('SessionPinningFilters', []))}+ {init_query_xml}+ </ConnectionPoolConfig>+ <CreatedDate>{_format_time(tg['CreatedDate'])}</CreatedDate>+ <UpdatedDate>{_format_time(tg['UpdatedDate'])}</UpdatedDate>"""+++def _db_proxy_target_xml(target):+ health = target.get("TargetHealth", {})+ tracked_cluster = target.get("TrackedClusterId")+ tracked_xml = (+ f"<TrackedClusterId>{_esc(tracked_cluster)}</TrackedClusterId>"+ if tracked_cluster+ else ""+ )+ reason = health.get("Reason")+ description = health.get("Description")+ return f"""<TargetArn>{target.get('TargetArn','')}</TargetArn>+ <Endpoint>{target.get('Endpoint','')}</Endpoint>+ {tracked_xml}+ <RdsResourceId>{_esc(target.get('RdsResourceId',''))}</RdsResourceId>+ <Port>{target.get('Port', 0)}</Port>+ <Type>{target.get('Type','RDS_INSTANCE')}</Type>+ <Role>{target.get('Role','READ_WRITE')}</Role>+ <TargetHealth>+ <State>{health.get('State','AVAILABLE')}</State>+ {f'<Reason>{reason}</Reason>' if reason else ''}+ {f'<Description>{_esc(description)}</Description>' if description else ''}+ </TargetHealth>"""+++def _xml(status, root_tag, inner):body = f"""<?xml version="1.0" encoding="UTF-8"?><{root_tag} xmlns="http://rds.amazonaws.com/doc/2014-10-31/">@@ -7692,6 +8891,19 @@ _ACTION_MAP = {"FailoverGlobalCluster": _failover_global_cluster,"EnableHttpEndpoint": _enable_http_endpoint,"DisableHttpEndpoint": _disable_http_endpoint,+ "CreateDBProxy": _create_db_proxy,+ "DescribeDBProxies": _describe_db_proxies,+ "ModifyDBProxy": _modify_db_proxy,+ "DeleteDBProxy": _delete_db_proxy,+ "CreateDBProxyEndpoint": _create_db_proxy_endpoint,+ "DescribeDBProxyEndpoints": _describe_db_proxy_endpoints,+ "ModifyDBProxyEndpoint": _modify_db_proxy_endpoint,+ "DeleteDBProxyEndpoint": _delete_db_proxy_endpoint,+ "DescribeDBProxyTargetGroups": _describe_db_proxy_target_groups,+ "ModifyDBProxyTargetGroup": _modify_db_proxy_target_group,+ "RegisterDBProxyTargets": _register_db_proxy_targets,+ "DeregisterDBProxyTargets": _deregister_db_proxy_targets,+ "DescribeDBProxyTargets": _describe_db_proxy_targets,}@@ -7752,6 +8964,8 @@ def reset():_db_cluster_param_groups.clear()_db_cluster_snapshots.clear()_option_groups.clear()+ _db_proxies.clear()+ _db_proxy_endpoints.clear()_global_clusters.clear()_tags.clear()_port_counter[0] = BASE_PORTdiff --git a/tests/test_glue.py b/tests/test_glue.pyindex 44bb4e23..9f20ce3c 100644--- a/tests/test_glue.py+++ b/tests/test_glue.py@@ -2317,3 +2317,72 @@ def test_glue_json_rpc_surface_unaffected():)assert status == 200assert "rpc_db" in _svc("glue")._databases+++def test_glue_spark_container_env_points_sdk_at_ministack(tmp_path, monkeypatch):+ """The Spark container env must carry AWS_ENDPOINT_URL so the script's own+ boto3 clients hit MiniStack rather than escaping to real AWS, which answers+ InvalidAccessKeyId for the emulator's credentials. Same injection the+ Lambda-container, CodeBuild and ECS RunTask executors already do. Only the+ spark.hadoop.fs.s3a.* conf covered Spark reads/writes."""+ from ministack.services import glue as _glue++ monkeypatch.setattr(_glue, "_ministack_network", "")+ monkeypatch.delenv("MINISTACK_HOST", raising=False)+ monkeypatch.delenv("EDGE_PORT", raising=False)++ created = {}+ archived = {}++ class _FakeContainer:+ def put_archive(self, path, data):+ import io+ import tarfile+ with tarfile.open(fileobj=io.BytesIO(+ data.read() if hasattr(data, "read") else data)) as tar:+ for m in tar.getmembers():+ archived[m.name] = tar.extractfile(m).read().decode()++ def start(self):+ pass++ def wait(self, timeout=None):+ return {"StatusCode": 0}++ def logs(self, tail=None):+ return b""++ def remove(self, force=False, v=False):+ pass++ class _FakeContainers:+ def get(self, name):+ raise RuntimeError("no such container")++ def create(self, **kwargs):+ created.update(kwargs)+ return _FakeContainer()++ class _FakeDocker:+ containers = _FakeContainers()++ script = tmp_path / "job.py"+ script.write_text("print('hi')")+ run = {"Id": "jr_test1492"}+ _glue._execute_spark_docker(+ run, {"Timeout": 1}, "envjob", {}, str(script), _FakeDocker())++ env = created["environment"]+ assert env["AWS_ENDPOINT_URL"] == "http://host.docker.internal:4566"+ # The SDK endpoint and the Spark S3A endpoint must agree.+ s3a = [c for c in created["command"]+ if isinstance(c, str) and c.startswith("spark.hadoop.fs.s3a.endpoint=")]+ assert s3a == [f"spark.hadoop.fs.s3a.endpoint={env['AWS_ENDPOINT_URL']}"]+ # spark-submit is handed the bootstrap, which patches create_client for+ # botocore versions predating AWS_ENDPOINT_URL (Glue 4.0 ships 1.27) and+ # then runs the real script as __main__.+ assert created["command"][-1] == "/tmp/_ministack_boot.py"+ assert set(archived) == {"job.py", "_ministack_boot.py"}+ assert "'/tmp/job.py'" in archived["_ministack_boot.py"]+ assert "create_client" in archived["_ministack_boot.py"]+ assert run["JobRunState"] == "SUCCEEDED"diff --git a/tests/test_rds.py b/tests/test_rds.pyindex b4997ac1..61c781fb 100644--- a/tests/test_rds.py+++ b/tests/test_rds.py@@ -12221,3 +12221,700 @@ def test_aurora_pg_replicating_reader_live(rds):with pytest.raises(psycopg2.Error) as excinfo:cursor.execute("INSERT INTO repl_rows VALUES (2, 'nope')")assert excinfo.value.pgcode == "25006"+++# ---------------------------------------------------------------------------+# RDS Proxy (control plane)+# ---------------------------------------------------------------------------++def proxy_subnets(ec2):+ vpc_id = ec2.create_vpc(CidrBlock="10.90.0.0/16")["Vpc"]["VpcId"]+ subnet_a = ec2.create_subnet(+ VpcId=vpc_id,+ CidrBlock="10.90.1.0/24",+ AvailabilityZone="us-east-1a",+ )["Subnet"]["SubnetId"]+ subnet_b = ec2.create_subnet(+ VpcId=vpc_id,+ CidrBlock="10.90.2.0/24",+ AvailabilityZone="us-east-1b",+ )["Subnet"]["SubnetId"]+ return vpc_id, [subnet_a, subnet_b]+++PROXY_AUTH = [{+ "AuthScheme": "SECRETS",+ "SecretArn": "arn:aws:secretsmanager:us-east-1:000000000000:secret:db",+ "IAMAuth": "DISABLED",+}]+++def _create_proxy(rds, subnets, name, **kwargs):+ kwargs.setdefault("EngineFamily", "POSTGRESQL")+ kwargs.setdefault("RoleArn", "arn:aws:iam::000000000000:role/rds-proxy-role")+ # AWS: "If you don't specify DefaultAuthScheme or specify this parameter+ # as NONE, you must specify the Auth option."+ if "DefaultAuthScheme" not in kwargs:+ kwargs.setdefault("Auth", PROXY_AUTH)+ return rds.create_db_proxy(+ DBProxyName=name, VpcSubnetIds=subnets, **kwargs+ )["DBProxy"]+++def test_rds_create_db_proxy_returns_documented_defaults(rds, proxy_subnets):+ vpc_id, subnets = proxy_subnets+ proxy = _create_proxy(rds, subnets, "parity-proxy")++ assert proxy["DBProxyArn"].startswith(+ "arn:aws:rds:us-east-1:000000000000:db-proxy:prx-"+ )+ assert proxy["Status"] == "available"+ assert proxy["EngineFamily"] == "POSTGRESQL"+ assert proxy["VpcId"] == vpc_id+ assert proxy["VpcSubnetIds"] == subnets+ # AWS documents these defaults on CreateDBProxy / DBProxy.+ assert proxy["IdleClientTimeout"] == 1800+ assert proxy["RequireTLS"] is False+ assert proxy["DebugLogging"] is False+ assert proxy["EndpointNetworkType"] == "IPV4"+ assert proxy["TargetConnectionNetworkType"] == "IPV4"+ assert proxy["Endpoint"].startswith("parity-proxy.proxy-")+ assert proxy["Endpoint"].endswith(".us-east-1.rds.amazonaws.com")+++def test_rds_create_db_proxy_creates_default_endpoint_and_target_group(+ rds, proxy_subnets,+):+ vpc_id, subnets = proxy_subnets+ proxy = _create_proxy(rds, subnets, "default-parts-proxy")++ endpoints = rds.describe_db_proxy_endpoints(+ DBProxyName="default-parts-proxy"+ )["DBProxyEndpoints"]+ assert len(endpoints) == 1+ endpoint = endpoints[0]+ assert endpoint["DBProxyEndpointName"] == "default-parts-proxy"+ assert endpoint["IsDefault"] is True+ assert endpoint["TargetRole"] == "READ_WRITE"+ assert endpoint["Endpoint"] == proxy["Endpoint"]+ assert endpoint["VpcId"] == vpc_id+ assert endpoint["DBProxyEndpointArn"].startswith(+ "arn:aws:rds:us-east-1:000000000000:db-proxy-endpoint:prx-endpoint-"+ )++ groups = rds.describe_db_proxy_target_groups(+ DBProxyName="default-parts-proxy"+ )["TargetGroups"]+ assert len(groups) == 1+ group = groups[0]+ assert group["TargetGroupName"] == "default"+ assert group["IsDefault"] is True+ assert group["Status"] == "available"+ assert group["TargetGroupArn"].startswith(+ "arn:aws:rds:us-east-1:000000000000:target-group:prx-tg-"+ )+ assert group["ConnectionPoolConfig"] == {+ "MaxConnectionsPercent": 100,+ "MaxIdleConnectionsPercent": 50,+ "ConnectionBorrowTimeout": 120,+ "SessionPinningFilters": [],+ }+++def test_rds_db_proxy_sqlserver_connection_pool_defaults(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "sqlserver-proxy", EngineFamily="SQLSERVER")++ config = rds.describe_db_proxy_target_groups(+ DBProxyName="sqlserver-proxy"+ )["TargetGroups"][0]["ConnectionPoolConfig"]+ # "Default: 10 for RDS for Microsoft SQL Server" / "for SQL Server,+ # MaxIdleConnectionsPercent is 5".+ assert config["MaxConnectionsPercent"] == 10+ assert config["MaxIdleConnectionsPercent"] == 5+++def test_rds_db_proxy_tags_and_auth_round_trip(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ proxy = _create_proxy(+ rds,+ subnets,+ "tagged-proxy",+ Auth=[{+ "Description": "main",+ "AuthScheme": "SECRETS",+ "SecretArn": "arn:aws:secretsmanager:us-east-1:000000000000:secret:db",+ "IAMAuth": "DISABLED",+ }],+ Tags=[{"Key": "env", "Value": "dev"}],+ )++ assert proxy["Auth"] == [{+ "Description": "main",+ "AuthScheme": "SECRETS",+ "SecretArn": "arn:aws:secretsmanager:us-east-1:000000000000:secret:db",+ "IAMAuth": "DISABLED",+ }]+ assert rds.list_tags_for_resource(+ ResourceName=proxy["DBProxyArn"]+ )["TagList"] == [{"Key": "env", "Value": "dev"}]+++def test_rds_db_proxy_duplicate_name_and_unknown_lookups(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "dup-proxy")++ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "dup-proxy")+ assert exc_info.value.response["Error"]["Code"] == "DBProxyAlreadyExistsFault"+ assert exc_info.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400++ with pytest.raises(ClientError) as exc_info:+ rds.describe_db_proxies(DBProxyName="missing-proxy")+ assert exc_info.value.response["Error"]["Code"] == "DBProxyNotFoundFault"+ assert exc_info.value.response["ResponseMetadata"]["HTTPStatusCode"] == 404++ with pytest.raises(ClientError) as exc_info:+ rds.describe_db_proxy_targets(+ DBProxyName="dup-proxy", TargetGroupName="not-default",+ )+ assert exc_info.value.response["Error"]["Code"] == "DBProxyTargetGroupNotFoundFault"+++def test_rds_db_proxy_rejects_invalid_subnets(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ with pytest.raises(ClientError) as exc_info:+ _create_proxy(+ rds, [subnets[0], "subnet-does-not-exist"], "bad-subnet-proxy",+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidSubnet"+++def test_rds_db_proxy_endpoint_lifecycle(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "endpoint-proxy")++ endpoint = rds.create_db_proxy_endpoint(+ DBProxyName="endpoint-proxy",+ DBProxyEndpointName="reader-endpoint",+ VpcSubnetIds=subnets,+ TargetRole="READ_ONLY",+ )["DBProxyEndpoint"]+ assert endpoint["IsDefault"] is False+ assert endpoint["TargetRole"] == "READ_ONLY"+ assert endpoint["Endpoint"].startswith("reader-endpoint.endpoint.proxy-")++ renamed = rds.modify_db_proxy_endpoint(+ DBProxyEndpointName="reader-endpoint",+ NewDBProxyEndpointName="reader-endpoint-2",+ VpcSecurityGroupIds=["sg-01234567"],+ )["DBProxyEndpoint"]+ assert renamed["DBProxyEndpointName"] == "reader-endpoint-2"+ assert renamed["VpcSecurityGroupIds"] == ["sg-01234567"]+ assert renamed["Endpoint"].startswith("reader-endpoint-2.endpoint.proxy-")++ deleted = rds.delete_db_proxy_endpoint(+ DBProxyEndpointName="reader-endpoint-2"+ )["DBProxyEndpoint"]+ assert deleted["Status"] == "deleting"+ assert [+ e["DBProxyEndpointName"]+ for e in rds.describe_db_proxy_endpoints(+ DBProxyName="endpoint-proxy"+ )["DBProxyEndpoints"]+ ] == ["endpoint-proxy"]+++def test_rds_db_proxy_default_endpoint_cannot_be_modified_or_deleted(+ rds, proxy_subnets,+):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "immutable-default-proxy")++ with pytest.raises(ClientError) as exc_info:+ rds.modify_db_proxy_endpoint(+ DBProxyEndpointName="immutable-default-proxy",+ VpcSecurityGroupIds=["sg-01234567"],+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "InvalidDBProxyEndpointStateFault"+ )++ with pytest.raises(ClientError) as exc_info:+ rds.delete_db_proxy_endpoint(+ DBProxyEndpointName="immutable-default-proxy",+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "InvalidDBProxyEndpointStateFault"+ )+++def test_rds_db_proxy_target_registration(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "target-proxy")+ rds.create_db_instance(+ DBInstanceIdentifier="proxy-target-pg",+ DBInstanceClass="db.t3.micro",+ Engine="postgres",+ MasterUsername="admin",+ MasterUserPassword="password123",+ AllocatedStorage=20,+ )++ targets = rds.register_db_proxy_targets(+ DBProxyName="target-proxy",+ TargetGroupName="default",+ DBInstanceIdentifiers=["proxy-target-pg"],+ )["DBProxyTargets"]+ assert len(targets) == 1+ target = targets[0]+ assert target["Type"] == "RDS_INSTANCE"+ assert target["Role"] == "READ_WRITE"+ assert target["RdsResourceId"] == "proxy-target-pg"+ assert target["TargetArn"] == (+ "arn:aws:rds:us-east-1:000000000000:db:proxy-target-pg"+ )+ assert target["TargetHealth"]["State"] == "AVAILABLE"++ with pytest.raises(ClientError) as exc_info:+ rds.register_db_proxy_targets(+ DBProxyName="target-proxy",+ DBInstanceIdentifiers=["proxy-target-pg"],+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "DBProxyTargetAlreadyRegisteredFault"+ )++ with pytest.raises(ClientError) as exc_info:+ rds.register_db_proxy_targets(+ DBProxyName="target-proxy",+ DBInstanceIdentifiers=["no-such-instance"],+ )+ assert exc_info.value.response["Error"]["Code"] == "DBInstanceNotFound"++ with pytest.raises(ClientError) as exc_info:+ rds.deregister_db_proxy_targets(+ DBProxyName="target-proxy",+ DBInstanceIdentifiers=["no-such-instance"],+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "DBProxyTargetNotFoundFault"+ )++ rds.deregister_db_proxy_targets(+ DBProxyName="target-proxy",+ DBInstanceIdentifiers=["proxy-target-pg"],+ )+ assert rds.describe_db_proxy_targets(+ DBProxyName="target-proxy"+ )["Targets"] == []+ rds.delete_db_instance(+ DBInstanceIdentifier="proxy-target-pg", SkipFinalSnapshot=True,+ )+++def test_rds_db_proxy_cluster_target_is_tracked_cluster(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "cluster-target-proxy", EngineFamily="MYSQL")+ rds.create_db_cluster(+ DBClusterIdentifier="proxy-target-cluster",+ Engine="aurora-mysql",+ MasterUsername="admin",+ MasterUserPassword="password123",+ )++ target = rds.register_db_proxy_targets(+ DBProxyName="cluster-target-proxy",+ DBClusterIdentifiers=["proxy-target-cluster"],+ )["DBProxyTargets"][0]+ assert target["Type"] == "TRACKED_CLUSTER"+ assert target["TrackedClusterId"] == "proxy-target-cluster"+ assert target["RdsResourceId"] == "proxy-target-cluster"+ assert target["TargetArn"] == (+ "arn:aws:rds:us-east-1:000000000000:cluster:proxy-target-cluster"+ )+ rds.delete_db_cluster(+ DBClusterIdentifier="proxy-target-cluster", SkipFinalSnapshot=True,+ )+++def test_rds_modify_db_proxy_target_group_connection_pool(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "pool-proxy")++ group = rds.modify_db_proxy_target_group(+ DBProxyName="pool-proxy",+ TargetGroupName="default",+ ConnectionPoolConfig={+ "MaxConnectionsPercent": 80,+ "MaxIdleConnectionsPercent": 40,+ "ConnectionBorrowTimeout": 30,+ "SessionPinningFilters": ["EXCLUDE_VARIABLE_SETS"],+ "InitQuery": "SET x=1",+ },+ )["DBProxyTargetGroup"]+ assert group["ConnectionPoolConfig"] == {+ "MaxConnectionsPercent": 80,+ "MaxIdleConnectionsPercent": 40,+ "ConnectionBorrowTimeout": 30,+ "SessionPinningFilters": ["EXCLUDE_VARIABLE_SETS"],+ "InitQuery": "SET x=1",+ }++ with pytest.raises(ClientError) as exc_info:+ rds.modify_db_proxy_target_group(+ DBProxyName="pool-proxy",+ TargetGroupName="default",+ NewName="renamed",+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+++def test_rds_modify_and_delete_db_proxy(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "mutable-proxy")++ proxy = rds.modify_db_proxy(+ DBProxyName="mutable-proxy",+ NewDBProxyName="mutable-proxy-2",+ RequireTLS=True,+ DebugLogging=True,+ IdleClientTimeout=600,+ SecurityGroups=["sg-0abcdef0"],+ RoleArn="arn:aws:iam::000000000000:role/other-role",+ )["DBProxy"]+ assert proxy["DBProxyName"] == "mutable-proxy-2"+ assert proxy["RequireTLS"] is True+ assert proxy["DebugLogging"] is True+ assert proxy["IdleClientTimeout"] == 600+ assert proxy["VpcSecurityGroupIds"] == ["sg-0abcdef0"]+ assert proxy["RoleArn"] == "arn:aws:iam::000000000000:role/other-role"+ assert proxy["Endpoint"].startswith("mutable-proxy-2.proxy-")++ # The default endpoint follows the rename.+ endpoints = rds.describe_db_proxy_endpoints(+ DBProxyName="mutable-proxy-2"+ )["DBProxyEndpoints"]+ assert [e["DBProxyEndpointName"] for e in endpoints] == ["mutable-proxy-2"]++ deleted = rds.delete_db_proxy(DBProxyName="mutable-proxy-2")["DBProxy"]+ assert deleted["Status"] == "deleting"+ with pytest.raises(ClientError) as exc_info:+ rds.describe_db_proxies(DBProxyName="mutable-proxy-2")+ assert exc_info.value.response["Error"]["Code"] == "DBProxyNotFoundFault"+ # Deleting the proxy takes its endpoints with it.+ with pytest.raises(ClientError) as exc_info:+ rds.describe_db_proxy_endpoints(DBProxyName="mutable-proxy-2")+ assert exc_info.value.response["Error"]["Code"] == "DBProxyNotFoundFault"+++def test_rds_db_proxy_rejects_invalid_names_and_engine_family(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets++ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "9-starts-with-digit")+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"++ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "trailing-hyphen-")+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"++ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "oracle-proxy", EngineFamily="ORACLE")+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+++def test_rds_db_proxy_requires_auth_without_iam_default_scheme(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets++ # "If you don't specify DefaultAuthScheme or specify this parameter as+ # NONE, you must specify the Auth option."+ with pytest.raises(ClientError) as exc_info:+ rds.create_db_proxy(+ DBProxyName="no-auth-proxy",+ EngineFamily="POSTGRESQL",+ RoleArn="arn:aws:iam::000000000000:role/rds-proxy-role",+ VpcSubnetIds=subnets,+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "InvalidParameterCombination"+ )++ with pytest.raises(ClientError) as exc_info:+ rds.create_db_proxy(+ DBProxyName="none-scheme-proxy",+ EngineFamily="POSTGRESQL",+ RoleArn="arn:aws:iam::000000000000:role/rds-proxy-role",+ VpcSubnetIds=subnets,+ DefaultAuthScheme="NONE",+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "InvalidParameterCombination"+ )++ # IAM_AUTH stands alone.+ proxy = rds.create_db_proxy(+ DBProxyName="iam-auth-proxy",+ EngineFamily="POSTGRESQL",+ RoleArn="arn:aws:iam::000000000000:role/rds-proxy-role",+ VpcSubnetIds=subnets,+ DefaultAuthScheme="IAM_AUTH",+ )["DBProxy"]+ assert proxy["DefaultAuthScheme"] == "IAM_AUTH"+ assert proxy["Auth"] == []+++def test_rds_db_proxy_validates_documented_ranges(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets++ # "Constraints: 1 to 28,800"+ for bad in (0, 28801):+ with pytest.raises(ClientError) as exc_info:+ _create_proxy(+ rds, subnets, "timeout-proxy", IdleClientTimeout=bad,+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"++ _create_proxy(rds, subnets, "range-proxy")+ for field, bad in (+ ("MaxConnectionsPercent", 0),+ ("MaxConnectionsPercent", 101),+ ("ConnectionBorrowTimeout", 301),+ ):+ with pytest.raises(ClientError) as exc_info:+ rds.modify_db_proxy_target_group(+ DBProxyName="range-proxy",+ TargetGroupName="default",+ ConnectionPoolConfig={field: bad},+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"++ # "Must be between 0 and the value of MaxConnectionsPercent."+ with pytest.raises(ClientError) as exc_info:+ rds.modify_db_proxy_target_group(+ DBProxyName="range-proxy",+ TargetGroupName="default",+ ConnectionPoolConfig={+ "MaxConnectionsPercent": 50,+ "MaxIdleConnectionsPercent": 60,+ },+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"++ # "If you specify MaxIdleConnectionsPercent, then you must also include a+ # value for MaxConnectionsPercent."+ with pytest.raises(ClientError) as exc_info:+ rds.modify_db_proxy_target_group(+ DBProxyName="range-proxy",+ TargetGroupName="default",+ ConnectionPoolConfig={"MaxIdleConnectionsPercent": 10},+ )+ assert exc_info.value.response["Error"]["Code"] == (+ "InvalidParameterCombination"+ )+++def test_rds_db_proxy_max_idle_defaults_to_half_of_max_connections(+ rds, proxy_subnets,+):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "half-proxy")++ # "The default value is half of the value of MaxConnectionsPercent. For+ # example, if MaxConnectionsPercent is 80, then the default value of+ # MaxIdleConnectionsPercent is 40."+ config = rds.modify_db_proxy_target_group(+ DBProxyName="half-proxy",+ TargetGroupName="default",+ ConnectionPoolConfig={"MaxConnectionsPercent": 80},+ )["DBProxyTargetGroup"]["ConnectionPoolConfig"]+ assert config["MaxConnectionsPercent"] == 80+ assert config["MaxIdleConnectionsPercent"] == 40+ assert config["ConnectionBorrowTimeout"] == 120+++def test_rds_db_proxy_rejects_enum_values(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets++ for field, bad in (+ ("DefaultAuthScheme", "PASSWORD"),+ ("EndpointNetworkType", "IPV5"),+ ("TargetConnectionNetworkType", "DUAL"),+ ):+ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "enum-proxy", **{field: bad})+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+++def test_rds_db_proxy_sqlserver_endpoint_must_be_read_write(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "mssql-proxy", EngineFamily="SQLSERVER")++ # "The only role that proxies for RDS for Microsoft SQL Server support is+ # READ_WRITE."+ with pytest.raises(ClientError) as exc_info:+ rds.create_db_proxy_endpoint(+ DBProxyName="mssql-proxy",+ DBProxyEndpointName="mssql-reader",+ VpcSubnetIds=subnets,+ TargetRole="READ_ONLY",+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+++def test_rds_db_proxy_target_engine_must_match_engine_family(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "family-proxy", EngineFamily="MYSQL")+ rds.create_db_instance(+ DBInstanceIdentifier="family-pg",+ DBInstanceClass="db.t3.micro",+ Engine="postgres",+ MasterUsername="admin",+ MasterUserPassword="password123",+ AllocatedStorage=20,+ )++ with pytest.raises(ClientError) as exc_info:+ rds.register_db_proxy_targets(+ DBProxyName="family-proxy",+ DBInstanceIdentifiers=["family-pg"],+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+ rds.delete_db_instance(+ DBInstanceIdentifier="family-pg", SkipFinalSnapshot=True,+ )+++def test_rds_db_proxy_takes_a_single_target(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "single-target-proxy")+ for identifier in ("single-pg-a", "single-pg-b"):+ rds.create_db_instance(+ DBInstanceIdentifier=identifier,+ DBInstanceClass="db.t3.micro",+ Engine="postgres",+ MasterUsername="admin",+ MasterUserPassword="password123",+ AllocatedStorage=20,+ )++ rds.register_db_proxy_targets(+ DBProxyName="single-target-proxy",+ DBInstanceIdentifiers=["single-pg-a"],+ )+ # "Each proxy can be associated with a single target DB instance."+ with pytest.raises(ClientError) as exc_info:+ rds.register_db_proxy_targets(+ DBProxyName="single-target-proxy",+ DBInstanceIdentifiers=["single-pg-b"],+ )+ assert exc_info.value.response["Error"]["Code"] == "InvalidParameterValue"+ assert len(rds.describe_db_proxy_targets(+ DBProxyName="single-target-proxy"+ )["Targets"]) == 1++ for identifier in ("single-pg-a", "single-pg-b"):+ rds.delete_db_instance(+ DBInstanceIdentifier=identifier, SkipFinalSnapshot=True,+ )+++def test_rds_describe_db_proxies_paginates(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ names = [f"page-proxy-{i}" for i in range(3)]+ for name in names:+ _create_proxy(rds, subnets, name)++ # "Constraints: Minimum 20, maximum 100." botocore enforces the range+ # client-side, so drive the server check over the raw Query API.+ import requests+ response = requests.post(+ ENDPOINT,+ data={"Action": "DescribeDBProxies", "Version": "2014-10-31",+ "MaxRecords": "19"},+ headers={"Authorization": "AWS4-HMAC-SHA256 "+ "Credential=test/20260824/us-east-1/rds/aws4_request"},+ timeout=10,+ )+ assert response.status_code == 400+ assert "<Code>InvalidParameterValue</Code>" in response.text++ first = rds.describe_db_proxies(MaxRecords=20)+ assert "Marker" not in first++ seen = []+ for page in rds.get_paginator("describe_db_proxies").paginate(+ PaginationConfig={"PageSize": 20},+ ):+ seen.extend(p["DBProxyName"] for p in page["DBProxies"])+ assert set(names).issubset(set(seen))+ assert len(seen) == len(set(seen))+++def _delete_all_db_proxies(rds):+ for proxy in rds.describe_db_proxies(MaxRecords=100)["DBProxies"]:+ rds.delete_db_proxy(DBProxyName=proxy["DBProxyName"])+++def test_rds_db_proxy_quota(rds, proxy_subnets):+ _vpc_id, subnets = proxy_subnets+ # The quota is account/Region-wide, so start and finish from a clean slate+ # rather than poisoning every later proxy test in this file.+ _delete_all_db_proxies(rds)+ try:+ # "Each AWS account ID is limited to 20 proxies."+ for i in range(20):+ _create_proxy(rds, subnets, f"quota-proxy-{i}")++ with pytest.raises(ClientError) as exc_info:+ _create_proxy(rds, subnets, "quota-proxy-over")+ assert exc_info.value.response["Error"]["Code"] == (+ "DBProxyQuotaExceededFault"+ )+ assert exc_info.value.response["ResponseMetadata"]["HTTPStatusCode"] == 400+ finally:+ _delete_all_db_proxies(rds)+++def test_rds_db_proxy_target_health_follows_the_backing_instance(+ rds, proxy_subnets,+):+ _vpc_id, subnets = proxy_subnets+ _create_proxy(rds, subnets, "health-proxy")+ rds.create_db_instance(+ DBInstanceIdentifier="health-pg",+ DBInstanceClass="db.t3.micro",+ Engine="postgres",+ MasterUsername="admin",+ MasterUserPassword="password123",+ AllocatedStorage=20,+ )+ target = rds.register_db_proxy_targets(+ DBProxyName="health-proxy", DBInstanceIdentifiers=["health-pg"],+ )["DBProxyTargets"][0]+ assert target["TargetHealth"]["State"] == "AVAILABLE"+ assert target["Endpoint"]++ def health():+ return rds.describe_db_proxy_targets(+ DBProxyName="health-proxy"+ )["Targets"][0]++ rds.stop_db_instance(DBInstanceIdentifier="health-pg")+ assert health()["TargetHealth"]["State"] == "UNAVAILABLE"+ rds.start_db_instance(DBInstanceIdentifier="health-pg")+ assert health()["TargetHealth"]["State"] == "AVAILABLE"++ # A target must not keep reporting itself available at an address that no+ # longer exists once its backing database is gone.+ rds.delete_db_instance(+ DBInstanceIdentifier="health-pg", SkipFinalSnapshot=True,+ )+ stale = health()+ assert stale["TargetHealth"]["State"] == "UNAVAILABLE"+ assert stale["TargetArn"] == ""+ assert stale["Endpoint"] == ""+ rds.deregister_db_proxy_targets(+ DBProxyName="health-proxy", DBInstanceIdentifiers=["health-pg"],+ )