I am trying to connect to a AWS RDS PosgreSQL database from a lambda in Go.
The authToken seems good in the logs.
creds := credentials.NewEnvCredentials()
authToken, err := rdsutils.BuildAuthToken("something.eu-west-3.rds.amazonaws.com", "eu-west-3", "Username", creds)
if err != nil {
fmt.Println("Cannot create db auth token")
return response.Status(500), err
}
// Create the DNS string for the DB connection
// // user:password@protocol(endpoint:port)/dbname?<params>
dnsStr := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=verify-full",
"Username", authToken, "something.eu-west-3.rds.amazonaws.com", "table_name",
)
db, err := sql.Open("postgres", dnsStr)
if err != nil {
fmt.Println("Cannot open db")
return response.Status(500), err
}
err = db.Ping()
if err != nil {
fmt.Println("Cannot ping db")
return response.Status(500), err
}
fmt.Println("Connection established")
I have an error on the db.Ping(), and in the logs I got
Cannot ping db
dial tcp: address tcp/something.eu-west-3.rds.amazonaws.com: unknown port: OpError
null
I use the pq library, imported as _ "github.com/lib/pq"
I have tried adding the default port 5432 in the url after the host, but with no results.
I'm sure I'm missing a stupid key point, plz halp