rdsauth

module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 4, 2025 License: MIT

README

RDS IAM Token Authentication

Go Reference CI

  • RDS IAM authentication tokens are valid for 15 minutes.
  • IAM database authentication throttles connections at 200 new connections per second.
  • Connections that use the same authentication token are not throttled. It is recommended that you reuse authentication tokens when possible.

Usage

import (
	"database/sql"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/go-sql-driver/mysql"
	rdsauth "github.com/errm/rdsauth/mysql"
)

func main() {
	// Load AWS configuration
	cfg, _ := config.LoadDefaultConfig(context.TODO())

	// Configure MySQL connection
	mysqlConfig := mysql.NewConfig()
	mysqlConfig.User = "dbuser"
        mysqlConfig.Addr = "db-instance.region.rds.amazonaws.com:3306"
        mysqlConfig.Net = "tcp"

        // Register the token provider
        mysqlCfg.Apply(mysql.BeforeConnect(rdsauth.TokenProvider(cfg, 60*time.Second)))

        connector, _ := mysql.NewConnector(mysqlConfig)

	// Open database connection
	db, _ := sql.OpenDB(connector)
	defer db.Close()
	err := db.Ping()
	if err != nil {
		log.Fatal(err)
	}
}

Directories

Path Synopsis
Package mysql provides a token provider for AWS RDS IAM database authentication.
Package mysql provides a token provider for AWS RDS IAM database authentication.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL