0

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.

1 Answer 1

1

This error would only occur for one reason which is invalid authentication information. Perform the following checks:

Check the username is correct (is postgres the username you specified when creating the RDS DB, you can validate this in the console) Check the password is correct Assuming both of these values you specified you believe to be correct, you should reset the password from the RDS management console.

You can also check this useful resource:

https://www.freecodecamp.org/news/aws-lambda-rds/

Sign up to request clarification or add additional context in comments.

1 Comment

But that code isn't even using a password it is using the IAM authentication that is connected to that specific lambda service.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.