AWS SDK for Go (PILOT)
API Reference

PREVIEW DOCUMENTATION - This is a preview of a new format for the AWS SDK for Go API Reference documentation. For the current AWS SDK for Go API Reference, see https://docs.aws.amazon.com/sdk-for-go/api/.

We welcome your feedback on this new version of the documentation. Send your comments to aws-sdkdocs-feedback@amazon.com.

BuildAuthToken

import "github.com/aws/aws-sdk-go/service/rds/rdsutils"

func BuildAuthToken(endpoint, region, dbUser string, creds *credentials.Credentials) (string, error)

BuildAuthToken will return an authorization token used as the password for a DB connection.

  • endpoint - Endpoint consists of the port needed to connect to the DB. <host>:<port>

  • region - Region is the location of where the DB is

  • dbUser - User account within the database to sign in with

  • creds - Credentials to be signed with

The following example shows how to use BuildAuthToken to create an authentication token for connecting to a MySQL database in RDS.

authToken, err := BuildAuthToken(dbEndpoint, awsRegion, dbUser, awsCreds) // Create the MySQL DNS string for the DB connection // user:password@protocol(endpoint)/dbname?<params> connectStr = fmt.Sprintf("%s:%s@tcp(%s)/%s?allowCleartextPasswords=true&tls=rds", dbUser, authToken, dbEndpoint, dbName, ) // Use db to perform SQL operations on database db, err := sql.Open("mysql", connectStr)

See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.html for more information on using IAM database authentication with RDS.

endpoint

Type: string

region

Type: string

dbUser

Type: string

creds

Type: *credentials.Credentials

string

Type: string

error

Type: error

On this page: