https://github.com/labd/go-rds-iam
A SQL Driver for connecting to AWS RDS instances via IAM roles
https://github.com/labd/go-rds-iam
go rds-iam-authentication
Last synced: 10 months ago
JSON representation
A SQL Driver for connecting to AWS RDS instances via IAM roles
- Host: GitHub
- URL: https://github.com/labd/go-rds-iam
- Owner: labd
- License: mit
- Created: 2022-11-08T16:09:09.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-09T12:58:40.000Z (over 3 years ago)
- Last Synced: 2025-05-25T02:44:33.065Z (about 1 year ago)
- Topics: go, rds-iam-authentication
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RDS IAM SQL Driver for Go
## Usage
Make sure you have set the env var `AWS_REGION` to the region you want to
connect to.
## Example
```go
package main
import (
"context"
"database/sql"
"fmt"
"github.com/xo/dburl"
_ "github.com/labd/go-rds-iam/rdsiam"
)
// Register the custom schema with dburl
func init() {
dburl.Register(dburl.Scheme{
Driver: "postgresql-rdsiam",
Generator: dburl.GenPostgres,
Transport: dburl.TransportUnix,
Opaque: false,
Aliases: []string{"postgresql-rdsiam"},
Override: "",
})
}
func main() {
db, err := dburl.Open("postgresql-rdsiam://iam-role@rds-server/my-database")
if err != nil {
panic(err)
}
defer db.Close()
ctx := context.Background()
rows, err := db.QueryContext(ctx, `SELECT 'foobar' AS one`)
if err != nil {
panic(err)
}
for rows.Next() {
var value string
rows.Scan(&value)
fmt.Println("Selected:", value)
}
}
// alternative skips registering the url with dburl
func alternative() {
dsn, err := dburl.Parse("postgres://iam-role@rds-server/my-database")
if err != nil {
panic(err)
}
db, err := sql.Open("postgresql-rdsiam", dsn.DSN)
if err != nil {
panic(err)
}
defer db.Close()
}
```