

# Cleaning up resources

To avoid charges, remove the test resources that you created in this tutorial. Remove the routing data first, then the member clusters, and then the database cluster group for Aurora.

If you added clusters that you already run, remove them from the tutorial group, but don't delete the clusters. On version 8.4.900, DB instances run only in clusters that belong to a group, so delete a member cluster's DB instances before you remove it. A removed cluster keeps its storage and backups but can't serve connections. To take an existing cluster out of a group that you keep using, see [Removing a member cluster](databaseclustergroups-member-clusters.md#databaseclustergroups-removing-members).

## Removing the tutorial resources
<a name="databaseclustergroups-getting-started-clean-up"></a>

If you enabled routing, first remove the routing data. A `DELETE` with no `WHERE` clause removes up to 1,000 data mappings from across the group, and skips mappings that scaleout tables use. Delete the tutorial row by name.

**To remove the routing data**

1. At the routing endpoint, as the administrative router user, delete the database-level mapping row. An empty `router_table_name` selects only the database-level row.

   ```sql
   DELETE FROM dbclustergroup_sys.data_mappings WHERE (router_db_name, router_table_name) = ('tenant_0001', '');
   ```

1. At the routing endpoint, drop the router user.

   ```sql
   DROP USER 'app_user'@'%';
   ```

1. On each member cluster, through its own cluster endpoint, drop `app_user`.

   ```sql
   DROP USER 'app_user'@'%';
   ```

1. On the first member cluster, through its own cluster endpoint, drop the tutorial database.

   ```sql
   DROP DATABASE tenant_0001;
   ```

Then remove the member clusters and delete the group. You can't delete a cluster while it's a member of a group, so remove it from the group first.

------
#### [ Console ]

**To remove the member clusters (console)**

1. Sign in to the AWS Management Console and open the Amazon RDS console at [https://console.aws.amazon.com/rds/](https://console.aws.amazon.com/rds/).

1. Delete every DB instance of each member cluster. On the **Databases** page, select each instance, choose **Actions**, and then choose **Delete**. Wait until the cluster shows no DB instances before you continue.

1. In the navigation pane, choose **Database cluster groups**, and then choose the group.

1. On the **Member clusters** tab, select a member cluster.

1. Choose **Actions**, and then choose **Remove from group**.

1. Confirm that you want to remove the cluster.

1. Repeat steps 4 through 6 for each remaining member cluster, one at a time.

For the checks to run before you remove a cluster from a group that you keep, see [Removing a cluster from a group](databaseclustergroups-member-clusters.md#databaseclustergroups-leaving-group).

**To delete the group (console)**

1. In the navigation pane, choose **Database cluster groups**, and then choose the group.

1. If routing is enabled, choose **Modify**, clear **Enable routing**, choose **Confirm**, and then choose **Save changes**. The console doesn't delete a group that has routing enabled.

1. Choose **Actions**, and then choose **Delete cluster group**.

1. Enter the group identifier to confirm the deletion, and then choose **Confirm**.

1. If you created clusters for the tutorial, delete them, as described in [Deleting Aurora DB clusters and DB instances](USER_DeleteCluster.md).

If deletion protection is on, or if you want to keep the group's automated backups, see [Deleting a database cluster group for Aurora](databaseclustergroups-group-lifecycle.md#databaseclustergroups-group-lifecycle-delete).

------
#### [ AWS CLI ]

**To remove the member clusters and delete the group (AWS CLI)**

1. Delete every DB instance of each member cluster (`aws rds delete-db-instance`), and wait until `describe-db-clusters` shows no `DBClusterMembers`.

1. With the AWS CLI, remove each member cluster, one at a time, with `RemoveDBClusterFromDBClusterGroup` (`aws rds remove-db-cluster-from-db-cluster-group`).

   ```bash
   aws rds remove-db-cluster-from-db-cluster-group --region {{REGION}} \
       --db-cluster-group-identifier {{GROUP_IDENTIFIER}} --db-cluster-identifier {{CLUSTER_IDENTIFIER}}
   ```

1. With the AWS CLI, delete the group with `DeleteDBClusterGroup` (`aws rds delete-db-cluster-group`).

   ```bash
   aws rds delete-db-cluster-group --region {{REGION}} --db-cluster-group-identifier {{GROUP_IDENTIFIER}}
   ```

1. If you created clusters for the tutorial, delete them, as described in [Deleting Aurora DB clusters and DB instances](USER_DeleteCluster.md).

------
#### [ Amazon RDS API ]

Call `RemoveDBClusterFromDBClusterGroup` with `DBClusterGroupIdentifier` and `DBClusterIdentifier` for each member cluster, one at a time. Then call `DeleteDBClusterGroup` with `DBClusterGroupIdentifier`. To delete clusters that you created for the tutorial, call `DeleteDBCluster`.

------

A removal doesn't check or delete the data mappings that name the cluster, so delete them first, as in the routing data procedure. If the member cluster is stopped, a `DELETE` of its data mappings fails with error 3168 until you remove the member cluster, so remove it first, then delete its mappings. On version 8.4.900, a removed member cluster keeps its storage and backups but has no DB instances, so it can't serve connections. For the full steps and checks, see [Adding and removing member clusters](databaseclustergroups-member-clusters.md) and [Creating, modifying, and deleting a database cluster group for Aurora](databaseclustergroups-group-lifecycle.md).

For the parameters of each call, see the [Amazon RDS API Reference](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/Welcome.html).

## Next steps
<a name="databaseclustergroups-getting-started-next-steps"></a>

Each of the following is a separate choice that you can make later. To run a group day to day, see [Managing a database cluster group for Aurora](databaseclustergroups-managing.md), including the following topics:
+ [Upgrading a database cluster group for Aurora in waves](databaseclustergroups-upgrades.md), to upgrade member clusters in waves.
+ [Backing up and restoring a database cluster group for Aurora](databaseclustergroups-backups.md), to back up the group and restore every member cluster to a consistent point in time.
+ [Monitoring database cluster groups for Aurora](databaseclustergroups-monitoring.md), to read member clusters side by side.

To bring the clusters that you run today into a group, see [Add member clusters](databaseclustergroups-gs-add-members.md). If your application already splits data across them, see [Describing existing data partitions with data mappings](databaseclustergroups-existing-split.md) and [Sending traffic through the routing layer](databaseclustergroups-routing-traffic.md).

### Placing and moving data when you use routing
<a name="databaseclustergroups-adopting-later"></a>

If you use routing, you choose placement and movement for one database or table at a time, when you're ready:
+ To decide where data lives and whether you need a routing key, see [Designing data placement](databaseclustergroups-choosing-routing.md).
+ To place databases or single tables on specific member clusters, see [Using database-level and table-level mappings](databaseclustergroups-mapping-levels.md).
+ To move a database or collocation to another member cluster with minimal downtime, use data movement. For more information, see [Moving data between member clusters](databaseclustergroups-data-movement.md).
+ To spread one table that outgrows a member cluster across several member clusters, see [Choosing a routing key and routing function](databaseclustergroups-routing-key.md) and [Creating and loading a scaleout table](databaseclustergroups-create-scaleout-table.md).

Before you place two databases on different member clusters, find the statements that join or write both of them. Split those statements, or keep those databases in one collocation.