Enable the regresql init method to work with AWS IAM authentication. Im not sure what the best method would be but a flag to use iam may be appropriate. Then a function similar to the following could be used to generate the necessary tokens.
package main
import (
"database/sql"
"fmt"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/rds/rdsutils"
_ "github.com/lib/pq"
)
func main() {
dbName := "app"
dbUser := "jane_doe"
dbHost := "mydb.123456789012.us-east-1.rds.amazonaws.com"
dbPort := 5432
dbEndpoint := fmt.Sprintf("%s:%d", dbHost, dbPort)
region := "us-east-1"
creds := credentials.NewEnvCredentials()
authToken, err := rdsutils.BuildAuthToken(dbEndpoint, region, dbUser, creds)
if err != nil {
panic(err)
}
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s",
dbHost, dbPort, dbUser, authToken, dbName,
)
db, err := sql.Open("postgres", dsn)
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err)
}
}
See the AWS IAM docs for more details on handling connections.
Enable the
regresql initmethod to work with AWS IAM authentication. Im not sure what the best method would be but a flag to use iam may be appropriate. Then a function similar to the following could be used to generate the necessary tokens.See the AWS IAM docs for more details on handling connections.