Getting started with Aurora data groups
In this tutorial, you create a data group named tenant42 on a DB cluster named orders-cluster-1, add a
database with a table to it, and move the data group to a second DB cluster named orders-cluster-2. The steps use the
AWS CLI and a SQL client such as psql. Each step links to the full topic.
You can also create, view, and move data groups in the Amazon RDS console. In the navigation pane, choose Data Groups. Each linked topic has the console procedure.
To keep this example simple, the data group uses the same KMS key as its DB cluster. To encrypt a data group with its own KMS key, see Encrypting data groups in Amazon Aurora.
-
Set up two DB clusters. You need a source DB cluster and a target DB cluster in the same AWS account and AWS Region. Both must run an engine version that supports data groups, use Aurora I/O-Optimized storage, have a writer DB instance, and have a cluster admin user with the same name. You can use existing DB clusters that meet these requirements. For the full list, see Requirements for Aurora data groups. For the IAM permissions that you need, see Prerequisites for using Aurora data groups.
To find the engine versions that support data groups, run the following command.
aws rds describe-db-engine-versions \ --engine aurora-postgresql \ --query "DBEngineVersions[?SupportsDataGroups].EngineVersion" \ --output textTo create the two DB clusters, run the following commands once for
orders-cluster-1and once fororders-cluster-2.ImportantThe DB clusters incur charges until you delete them. To delete them, follow the clean-up steps at the end of this tutorial.
Use the same engine version for both, down to the minor and patch level, and the same admin user name.
aws rds create-db-cluster \ --db-cluster-identifierorders-cluster-1\ --engine aurora-postgresql \ --engine-version19.0\ --storage-type aurora-iopt1 \ --master-usernamepostgres\ --manage-master-user-password aws rds create-db-instance \ --db-instance-identifierorders-cluster-1-instance-1\ --db-cluster-identifierorders-cluster-1\ --db-instance-classdb.r8g.large\ --engine aurora-postgresqlThe
--manage-master-user-passwordoption stores the admin user password in AWS Secrets Manager. For more information, see Password management with Amazon Aurora and AWS Secrets Manager.Wait until both DB clusters are
available. For more information, see Creating an Amazon Aurora DB cluster. -
Create a data group. The following command creates the
tenant42data group onorders-cluster-1.aws rds create-data-group \ --db-cluster-identifierorders-cluster-1\ --data-group-nametenant42Save the
DataGroupIdentifierfrom the output, such asdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111. You use it in the later steps.Run the following command until the status is
active.aws rds describe-data-groups \ --data-group-identifierdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --query "DataGroups[0].Status"For other options, such as a data group endpoint, see Creating a data group.
-
Add a database and map the admin user. Connect to the writer endpoint of
orders-cluster-1aspostgres, the cluster admin user that you set with--master-usernamein step 1. For more information, see Connecting to an Amazon Aurora DB cluster.Run the following SQL. It maps
postgresto the data group asEXPECT_NAME_MATCH, which a move needs, becausepostgrescreates and owns the database in the data group. Because you created both DB clusters withpostgresas the admin user, the role already exists on the target DB cluster, and you don't need to create another role. Then the SQL creates theordersdatabase in the data group and adds a table with 1,000 rows.You can also create a role for an application and map it to the data group. For more information, see Managing roles for data groups.
For more information about creating databases in a data group, see Creating or migrating databases in a data group.
-
Move the data group. Prepare the move to
orders-cluster-2. Prepare checks that the target DB cluster can take the data group. If the move is refused, see Before you move a data group.aws rds move-data-group \ --data-group-identifierdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --move-operation prepare-move \ --target-db-cluster-identifierorders-cluster-2Run the
describe-data-groupscommand from step 2 until the status isready-to-move. Then execute the move.aws rds move-data-group \ --data-group-identifierdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --move-operation execute-move \ --target-db-cluster-identifierorders-cluster-2Run the
describe-data-groupscommand again until the status isactive. For more information, see Moving a data group to another DB cluster. -
Check the result. The data group is now on
orders-cluster-2.aws rds describe-data-groups \ --data-group-identifierdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111\ --query "DataGroups[0].[Status,DBClusterIdentifier]" \ --output textThe output resembles the following example.
active orders-cluster-2Connect to the writer endpoint of
orders-cluster-2and count the rows. The query returns 1,000. Onorders-cluster-1, theordersdatabase no longer exists.For the other checks to run after a move, see After you move a data group.
Next, try the following:
-
To keep the same endpoint when a data group moves, see Data group endpoints.
-
To give an application role access to only its data group, see Managing roles for data groups.
-
To bring an existing database into a data group, see Migrating existing databases into a data group.
-
To see the load of each data group, see Monitoring data groups.
Clean up. When you no longer need the data group, drop its database, or migrate it to another data group. Then delete the data group. A delete fails if the data group still
holds databases. Connect to the writer endpoint of orders-cluster-2 and run the following SQL.
Then delete the data group. For more information, see Deleting a data group.
aws rds delete-data-group \ --data-group-identifierdg-a1b2c3d4-5678-90ab-cdef-EXAMPLE11111
To avoid ongoing charges, delete the DB clusters that you created for this tutorial. Run the following
commands once for orders-cluster-1 and once for orders-cluster-2. Wait until the DB instance is
deleted before you delete the DB cluster. For more information, see Deleting Aurora DB clusters and DB instances.
aws rds delete-db-instance \ --db-instance-identifierorders-cluster-1-instance-1aws rds delete-db-cluster \ --db-cluster-identifierorders-cluster-1\ --skip-final-snapshot