feat(rds): stop, start and reboot DB instances and clusters (#4071)

* feat(rds): stop, start and reboot DB instances and clusters

Add StopDBInstance, StartDBInstance, StopDBCluster, StartDBCluster and
RebootDBCluster. A stop reports "stopping", takes the optional snapshot,
removes the container and proxy and settles the record to "stopped"
while its identifier, endpoint, groups and Docker volume stay; a start
reports "starting" and brings the container back on the kept volume and
port. Cluster stop, start and reboot carry the member instances along.

StopDBInstance refuses cluster members, read replicas and their sources,
and anything not available; ModifyDBInstance refuses a stopped instance;
a stopped resource stays stopped across an emulator restart.

Closes #4043

* feat(rds): refuse starting a stopped cluster's member alone, serialize cluster lifecycle calls

StartDBInstance now refuses a cluster member as StopDBInstance does, and
both answer InvalidDBClusterStateFault, the fault the model lists for a
member on either call; a member started alone would have got a
standalone container on its own volume while the cluster stayed stopped.
stopDbCluster, startDbCluster and rebootDbCluster are synchronized like
the instance calls, so two concurrent starts cannot both see STOPPED.
The five handler arms use the shared required-parameter helper and the
central AwsException handling.

* test(rds): import DbInstanceStatus instead of qualifying it inline

AGENTS.md asks for imports over inline fully-qualified names; the file
already imports DbInstanceStatus.
This commit is contained in:
David authored and GitHub committed 2026-09-21 16:12:54 -04:00
1 parent c083aad12b
commit 1542c641a6
8 files changed
+910 -1

No files matched your search

@@ -14,7 +14,9 @@ import software.amazon.awssdk.services.rds.model.ConnectionPoolConfigurationInfo
import software.amazon.awssdk.services.rds.model.CreateDbProxyResponse;
import software.amazon.awssdk.services.rds.model.CreateDbSubnetGroupResponse;
import software.amazon.awssdk.services.rds.model.CreateOptionGroupResponse;
import software.amazon.awssdk.services.rds.model.DBInstance;
import software.amazon.awssdk.services.rds.model.DBProxyTarget;
import software.amazon.awssdk.services.rds.model.InvalidDbInstanceStateException;
import software.amazon.awssdk.services.rds.model.DescribeDbSubnetGroupsResponse;
import software.amazon.awssdk.services.rds.model.DescribeOptionGroupsResponse;
import software.amazon.awssdk.services.rds.model.DescribeOrderableDbInstanceOptionsResponse;
@@ -394,6 +396,36 @@ class RdsControlPlaneTest {
}
}
@Test
void sdkStopsAndStartsAStandaloneInstance() throws Exception {
String instanceName = TestFixtures.uniqueName("rds-stop-db");
try {
createDbInstance(rds, instanceName, "stop-secret");
String endpoint = rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
.dbInstances().get(0).endpoint().address();
DBInstance stopping = rds.stopDBInstance(b -> b.dbInstanceIdentifier(instanceName)).dbInstance();
assertThat(stopping.dbInstanceStatus()).isEqualTo("stopping");
assertThat(rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
.dbInstances().get(0).dbInstanceStatus()).isEqualTo("stopped");
assertThatThrownBy(() -> rds.stopDBInstance(b -> b.dbInstanceIdentifier(instanceName)))
.isInstanceOf(InvalidDbInstanceStateException.class);
assertThatThrownBy(() -> rds.modifyDBInstance(b -> b
.dbInstanceIdentifier(instanceName).masterUserPassword("changed-secret")))
.isInstanceOf(InvalidDbInstanceStateException.class);
DBInstance starting = rds.startDBInstance(b -> b.dbInstanceIdentifier(instanceName)).dbInstance();
assertThat(starting.dbInstanceStatus()).isEqualTo("starting");
DBInstance started = rds.describeDBInstances(b -> b.dbInstanceIdentifier(instanceName))
.dbInstances().get(0);
assertThat(started.dbInstanceStatus()).isEqualTo("available");
assertThat(started.endpoint().address()).isEqualTo(endpoint);
} finally {
deleteDbInstance(rds, instanceName);
}
}
private static CreateDbProxyResponse createIamProxy(RdsClient client, String name, List<String> vpcSubnetIds) {
return client.createDBProxy(b -> b
.dbProxyName(name)