'Unable to connect to Aurora Postgres RDS from .Net Core 5 application

I am attempting to build a .NET Core 5 application that retrieves data from an AWS Aurora Postgres RDS database. The authentication method set for this database is token based. The token is generated and appended to the connection string and I then attempt to create and open a connection:

var pwd = Amazon.RDS.Util.RDSAuthTokenGenerator(RegionEndpoint.USEast1, "pf-datastore-instance-1.ctml5dmanwfh.us-east-1.rds.amazonaws.com", 5432, "postgres"); 
var builder = new Npgsql.Npgsql.ConnectionStringBuilder(connectionStr)
{
   Password = pwd
};
var conn = new Npgsql.NpgsqlConnection(builder.ConnectionString);
conn.Open();

The connection string I have in my appsettings.json is like so:

"Host=pf-datastore-instance-1.ctml5dmanwfh.us-east-1.rds.amazonaws.com;Database=pbDataSettings;Username=postgres;Port=5432;SSL Mode=Require;Root Certificate=us-east-1-bundle.pfx;Trust Server Certificate=true;"

I am using Npgsql version 5.0.12.

For the Root Certificate *pfx file, I downloaded the *pem from Amazon's documentation, and then converted it to the *pfx file using the following command:

openssl pkcs12 -export -nokeys -out us-east-1-bundle.pfx -in us-east-1-bundle.pem

The error I get is simply: "PAM Authentication failed for user postgres"

I can connect to this database via pgAdmin and via VS Code using the Database Client extension. For both these connection methods I simply use the *pem file.

Any help would be appreciated...

Hasanain



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source