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.
- IAM Database Authentication for MySQL and PostgreSQL - Amazon Relational Database Service
- IAM Database Authentication - Amazon Aurora
- Managing connections with Amazon RDS Proxy - Amazon Aurora
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.