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 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.