We are trying to deploy a service for collecting test execution data for our production systems. That service tries to connect to a database (rds postgres) within the same vpc. It is possible to connect to the database with pg admin but nit from the lambda function.
My Code:
func initDB(host, user, dbname string, port int) *sql.DB {
dbHost := host
var dbName string = dbname
var dbUser string = user
var dbPort int = port
var dbEndpoint string = fmt.Sprintf("%s:%d", dbHost, dbPort)
var region string = "us-east-1"
cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
panic("configuration error: " + err.Error())
}
authenticationToken, err := auth.BuildAuthToken(
context.TODO(), dbEndpoint, region, dbUser, cfg.Credentials)
if err != nil {
panic("failed to create authentication token: " + err.Error())
}
dsn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s",
dbHost, dbPort, dbUser, authenticationToken, dbName,
)
db, err := sql.Open("postgres", dsn)
if err != nil {
panic(err)
}
err = db.Ping()
if err != nil {
panic(err) // fails here
}
return db
}
Error message: Exception: panic: pq: password authentication failed for user
I have tried using password authentication and get "password authentication failed" as well.