Skip to content

The rdsmysql package is a SQL driver for Amazon RDS.

License

Notifications You must be signed in to change notification settings

shogo82148/rdsmysql

Repository files navigation

GitHub Actions status PkgGoDev

rdsmysql

The rdsmysql package is a SQL driver that allows IAM Database Authentication for Amazon RDS and Amazon Aurora. It also supports connecting to the RDS proxy using IAM authentication.

rdsmysql v1 works with AWS SDK for Go v1:

import (
	"database/sql"

	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/shogo82148/rdsmysql"
)

func main() {
	// configure AWS session
	awsConfig := aws.NewConfig().WithRegion("ap-northeast-1")
	awsSession := session.Must(session.NewSession(awsConfig))

	// configure the connector
	cfg, err := mysql.ParseDSN("user:@tcp(db-foobar.ap-northeast-1.rds.amazonaws.com:3306)/")
	if err != nil {
		panic(err)
	}
	connector := &rdsmysql.Connector{
		Session: awsSession,
		Config:  cfg,
	}

	// open the database
	db := sql.OpenDB(connector)
	defer db.Close()

	// ... do something using db ...
}

If you use AWS SDK for Go v2, use rdsmysql v2.

Related Posts