https://github.com/errm/rdsauth
https://github.com/errm/rdsauth
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/errm/rdsauth
- Owner: errm
- License: mit
- Created: 2025-07-04T14:07:17.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-04T15:05:31.000Z (11 months ago)
- Last Synced: 2025-07-04T15:49:41.694Z (11 months ago)
- Language: Go
- Size: 6.84 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RDS IAM Token Authentication
[](https://pkg.go.dev/github.com/errm/rdsauth)
[](https://github.com/errm/rdsauth/actions/workflows/ci.yaml)
* 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
```go
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
mysqlConfig.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)
}
}
```