Amazon Aurora DSQL is provided as a Preview service.
To learn more, see Betas and Previews
Use the Golang to generate a token in Aurora DSQL
Note
Golang SDK does not provide the API to generate the token. The following code sample shows how to generate the authentication token for Golang.
Once your cluster is ACTIVE
, you can generate an authentication token.
The following example uses the following attributes to generate an authentication token for the admin role.
-
yourClusterEndpoint – endpoint of the cluster. Follows the format
your_cluster_identifier
.dsql.AWS_REGION
.on.aws -
region – The AWS Region, such as us-east-2 or us-east-1
-
action – needs to be specified based on the postgres user
-
If you are connecting as
admin
user, you use theDbConnectAdmin
action -
If you are connecting with a custom database role, you use the
DbConnect
action
-
func GenerateDbConnectAdminAuthToken(
yourClusterEndpoint
string,region
string,action
string) (string, error) { // Fetch credentials sess, err := session.NewSession() if err != nil { return "", err } creds, err := sess.Config.Credentials.Get() if err != nil { return "", err } staticCredentials := credentials.NewStaticCredentials( creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken, ) // The scheme is arbitrary and is only needed because validation of the URL requires one. endpoint := "https://" + yourClusterEndpoint req, err := http.NewRequest("GET", endpoint, nil) if err != nil { return "", err } values := req.URL.Query() values.Set("Action", action) req.URL.RawQuery = values.Encode() signer := v4.Signer{ Credentials: staticCredentials, } _, err = signer.Presign(req, nil, "dsql", region, 15*time.Minute, time.Now()) if err != nil { return "", err } url := req.URL.String()[len("https://"):] return url, nil }