Generating an authentication token in Amazon Aurora DSQL
To connect to Amazon Aurora DSQL with a SQL client, generate an authentication token to use as the password. This token is used only for authenticating the connection. After the connection is established, the connection remains valid even if the authentication token expires.
If you create an authentication token using the AWS console, the token automatically expires in one hour by default. If you use the AWS CLI or SDKs to create the token, the default is 15 minutes. The maximum duration is 604,800 seconds, which is one week. To connect to Aurora DSQL from your client again, you can use the same authentication token if it hasn't expired, or you can generate a new one.
To get started with generating a token, create an IAM policy and a cluster in Aurora DSQL. Then use the AWS console , AWS CLI, or the AWS SDKs to generate a token.
At a minimum, you must have the IAM permissions listed in Connecting to your cluster using IAM, depending on which database role you use to connect.
Topics
Use the AWS console to generate an authentication token in Aurora DSQL
Aurora DSQL authenticates users with a token rather than a password. You can generate the token from the console.
To generate an authentication token
-
Sign in to the AWS Management Console and open the Aurora DSQL console at https://console.aws.amazon.com/dsql
. -
Choose the cluster ID of the cluster for which you want to generate an authentication token. If you haven't yet created a cluster, follow the steps in Step 1: Create an Aurora DSQL single-Region cluster or Step 4 (Optional): Create a multi-Region cluster.
-
Choose Connect and then select Get Token.
-
Choose whether you want to connect as an
adminor with a custom database role. -
Copy the generated authentication token and use it for Access Aurora DSQL using SQL clients.
To learn more about custom database roles and IAM in Aurora DSQL, see Authentication and authorization for Aurora DSQL.
Use AWS CloudShell to generate an authentication token in Aurora DSQL
Before you can generate an authentication token using AWS CloudShell, make sure that you Create an Aurora DSQL cluster.
To generate an authentication token using AWS CloudShell
-
Sign in to the AWS Management Console and open the Aurora DSQL console at https://console.aws.amazon.com/dsql
. -
At the bottom left of the AWS console, choose AWS CloudShell.
-
Run the following command to generate an authentication token for the
adminrole. Replaceus-east-1with your Region andyour_cluster_endpointwith the endpoint of your own cluster.Note
If you're not connecting as
admin, usegenerate-db-connect-auth-tokeninstead.aws dsql generate-db-connect-admin-auth-token \ --expires-in 3600 \ --regionus-east-1\ --hostnameyour_cluster_endpointIf you run into issues, see Troubleshoot IAM and How can I troubleshoot access denied or unauthorized operation errors with an IAM policy?
. -
Use the following command to use
psqlto start a connection to your cluster.PGSSLMODE=require \ psql --dbname postgres \ --username admin \ --host cluster_endpoint -
You should see a prompt to provide a password. Copy the token that you generated, and make sure you don't include any additional spaces or characters. Paste it into the following prompt from
psql.Password for user admin: -
Press Enter. You should see a PostgreSQL prompt.
postgres=>If you get an access denied error, make sure that your IAM identity has the
dsql:DbConnectAdminpermission. If you have the permission and continue to get access deny errors, see Troubleshoot IAM and How can I troubleshoot access denied or unauthorized operation errors with an IAM policy?.
To learn more about custom database roles and IAM in Aurora DSQL, see Authentication and authorization for Aurora DSQL.
Use the AWS CLI to generate an authentication token in Aurora DSQL
When your cluster is ACTIVE, you can generate an authentication token on
the CLI by using the aws dsql command. Use either of the following
techniques:
-
If you are connecting with the
adminrole, use thegenerate-db-connect-admin-auth-tokenoption. -
If you are connecting with a custom database role, use the
generate-db-connect-auth-tokenoption.
The following example uses the following attributes to generate an authentication
token for the admin role.
-
your_cluster_endpoint– The endpoint of the cluster. It follows the format, as in the exampleyour_cluster_identifier.dsql.region.on.aws01abc2ldefg3hijklmnopqurstu.dsql.us-east-1.on.aws. -
region– The AWS Region, such asus-east-2orus-east-1.
The following examples set the expiration time for the token to expire in 3600 seconds (1 hour).
Use the SDKs to generate a token in Aurora DSQL
You can generate an authentication token for your cluster when it is in
ACTIVE status. The SDK examples use the following attributes to
generate an authentication token for the admin role:
-
your_cluster_endpoint(oryourClusterEndpoint) – The endpoint of your Aurora DSQL cluster. The naming format is, as in the exampleyour_cluster_identifier.dsql.region.on.aws01abc2ldefg3hijklmnopqurstu.dsql.us-east-1.on.aws. -
region(orRegionEndpoint) – The AWS Region in which your cluster is located, such asus-east-2orus-east-1.