Skip to content

Latest commit

 

History

History
55 lines (42 loc) · 2.19 KB

README.md

File metadata and controls

55 lines (42 loc) · 2.19 KB

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 v2 works with AWS SDK for Go v2:

import (
	"context"
	"database/sql"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/go-sql-driver/mysql"
	"github.com/shogo82148/rdsmysql/v2"
)

func main() {
	// configure AWS SDK
	awsConfig, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("ap-northeast-1"))
	if err != nil {
		panic(err)
	}

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

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

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

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

Related Posts