Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

Aurora DSQL with pgx

Overview

This code example demonstrates how to use pgx with Amazon Aurora DSQL. The example shows you how to connect to an Aurora DSQL cluster and perform basic database operations.

Aurora DSQL is a distributed SQL database service that provides high availability and scalability for your PostgreSQL-compatible applications. pgx is a popular PostgreSQL driver and toolkit for Go that provides high-performance database connectivity.

About the code example

This example uses the Aurora DSQL Go Connector which automatically handles IAM token generation for authentication.

The example demonstrates a flexible connection approach that works for both admin and non-admin users:

  • When connecting as an admin user, the example uses the public schema and generates an admin authentication token.
  • When connecting as a non-admin user, the example uses a custom myschema schema and generates a standard authentication token.

The code automatically detects the user type and adjusts its behavior accordingly.

Important

  • Running this code might result in charges to your AWS account.
  • We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see Grant least privilege.
  • This code is not tested in every AWS Region. For more information, see AWS Regional Services.

Run the example

Prerequisites

  • You must have an AWS account, and have your default credentials and AWS Region configured as described in the Globally configuring AWS SDKs and tools guide.
  • Go: Ensure you have Go 1.21+ installed.
go version

It should output something similar to go version go1.21 or higher.

Run the code

The example demonstrates the following operations:

  • Opening a connection pool to an Aurora DSQL cluster
  • Running concurrent queries using the pool
  • Automatic IAM token generation for authentication

The example is designed to work with both admin and non-admin users.

Note: running the example will use actual resources in your AWS account and may incur charges.

Set environment variables for your cluster details:

# e.g. "foo0bar1baz2quux3quuux4.dsql.us-east-1.on.aws"
export CLUSTER_ENDPOINT="<your endpoint>"

Run the example:

go test ./test/... -v

The example contains comments explaining the code and the operations being performed.

Additional resources

Note: The connector automatically extracts the region from the cluster endpoint and defaults to the postgres database.


Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0