Getting started with Aurora DSQL
Amazon Aurora DSQL is a serverless, fully managed, distributed relational database optimized for transactional workloads. In the following sections, you'll learn how to create single-Region and multi-Region Aurora DSQL clusters, connect to them, and create and load a sample schema. You will access clusters with the AWS Console and optionally interact with your database using other PostgreSQL clients. By the end, you'll have a working Aurora DSQL cluster set up that is ready to use for test or production workloads.
Topics
Prerequisites
Before you can begin using Aurora DSQL, make sure you meet the following prerequisites:
-
Your IAM identity must have permission to sign in to the console.
-
Your IAM identity must meet the following criteria:
-
Access to perform any action on any resource in your AWS account
-
AmazonAuroraDSQLConsoleFullAccessAWS managed policy is attached.
-
Step 1: Create an Aurora DSQL single-Region cluster
The basic unit of Aurora DSQL is the cluster, which is where you store your data. In this task, you create a cluster in a single AWS Region.
To create a single-Region cluster in Aurora DSQL
-
Sign in to the AWS Management Console and open the Aurora DSQL console at https://console.aws.amazon.com/dsql
. -
Choose Create cluster.
-
In Cluster topology, choose Single Region.
-
In Cluster configuration, choose one of the following:
-
Quick create to create the cluster with recommended settings. You can change some settings, such as Tag: Name and deletion protection, before you create the cluster.
-
Advanced configuration to control all settings, including encryption and resource-based policies.
-
-
(Optional) If you chose Advanced configuration, do any of the following:
-
In Name and tags, change the value of the default Name tag, or choose Add additional tags.
-
In Cluster settings, select Customize encryption settings (advanced) to choose or create an AWS KMS key. If you use a customer managed key, make sure that the key policy grants Aurora DSQL the required permissions. For more information, see Key policy for a customer managed key.
-
In Cluster settings, keep Enable deletion protection selected to prevent a delete operation from removing your cluster. The console selects it by default.
-
In Cluster settings, select Add resource-based policy to specify access control policies for this cluster.
-
-
Choose Create cluster. The console opens the details page for your new cluster.
Step 2: Connect to your Aurora DSQL cluster
Aurora DSQL supports multiple ways to connect to your cluster, including the DSQL Query Editor, AWS CloudShell, the local psql client, and other PostgreSQL-compatible tools. In this step, you connect using the Aurora DSQL Query Editor, which provides a quick way to begin interacting with your new cluster.
To connect using the Query Editor
-
In the Aurora DSQL Console (https://console.aws.amazon.com/dsql
), open the Clusters page and confirm that your cluster creation has completed and its status is Active. -
Select your cluster from the list, or choose the Cluster ID to open the Cluster details page.
-
Choose Connect with Query editor.
-
Choose Connect as admin for the cluster that was just created.
-
Optionally you can connect with a custom role, see Using database roles and IAM authentication.
-
Step 3: Run sample SQL commands in Aurora DSQL
Test your Aurora DSQL cluster by running SQL statements. After opening the cluster in the Query Editor, select and run each sample query step by step.
Run sample SQL commands in Aurora DSQL
-
Create a schema named
test.CREATE SCHEMA IF NOT EXISTS test; -
Create a hello_world table that uses an automatically generated UUID as the primary key.
CREATE TABLE IF NOT EXISTS test.hello_world ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), message VARCHAR(255) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -
Insert a sample row.
INSERT INTO test.hello_world (message) VALUES ('Hello, World!!'); -
Read the inserted values.
SELECT * FROM test.hello_world; -
Optionally clean up.
DROP TABLE test.hello_world; DROP SCHEMA test;
Step 4 (Optional): Create a multi-Region cluster
A multi-Region cluster has two active peer Regions and one witness Region. When you create one, your current Region is the first peer Region, and you choose the second peer Region and the witness Region. You can choose these Regions from the Regions that support Aurora DSQL multi-Region clusters. All three Regions must be distinct. For more information about the supported Regions, see Multi-Region cluster availability.
- Peer Region
-
This is the Region that hosts the second active cluster. Both peer clusters accept read and write operations and present a single logical database with strong data consistency. Aurora DSQL replicates writes between the two peer Regions.
- Witness Region
-
This Region stores encrypted transaction logs, does not store encryption keys, has no managed endpoints, and does not make data accessible to users. The witness log supports transactional quorum if a Region becomes unavailable.
Use the following procedure to create a multi-Region cluster. The console creates a cluster in each of the two Regions and peers them for you. The procedures after it show cross-Region write replication and consistent reads from both Regional endpoints.
To create a multi-Region cluster
-
Sign in to the Aurora DSQL console
. -
In the navigation pane, choose Clusters.
-
Choose Create cluster.
-
In Cluster topology, choose 2 active Regions + Witness.
-
In Cluster configuration, choose one of the following:
-
Quick create to create the clusters with recommended settings. Peer cluster 1 is in your current Region. To change the Region for Peer cluster 2 or Witness peer, choose a Region in the Region row of the table.
-
Advanced configuration to control all settings for each Region. In Regions, choose the Peer cluster 2 Region and the Witness Region.
-
-
(Optional) If you chose Advanced configuration, change the settings for each Region in Name and tags, Encryption key, Deletion protection, and Resource-based policy - optional. If you use a customer managed key, make sure that the key policy grants Aurora DSQL the required permissions. For more information, see Key policy for a customer managed key.
-
Choose Create cluster. The console creates the cluster in your current Region and opens its details page. A notification shows the progress while the console creates the second cluster and peers the two clusters.
To connect to your second cluster
-
Open the Aurora DSQL console and choose the Region for your second cluster.
-
Choose Clusters.
-
Select the row for the second cluster in your multi-Region cluster.
-
Choose Connect with Query editor.
-
Choose Connect as admin.
-
Create a sample schema and table, and insert data by following the steps in Step 3: Run sample SQL commands in Aurora DSQL.
To query data in the second cluster from the Region hosting your initial cluster
-
In the Aurora DSQL console, choose the Region for your initial cluster.
-
Choose Clusters.
-
Select the row for the second cluster in your multi-Region cluster.
-
Choose Connect with Query editor.
-
Choose Connect as admin.
-
Query the data that you inserted into the second cluster.
Example
SELECT * FROM test.hello_world;
Troubleshooting
See the Troubleshooting section of the Aurora DSQL documentation.