When creating an rds.DatabaseCluster and a Role with the option credentials: rds.Credentials.fromGeneratedSecret("my-username"),, the Lambda function returns the following error:
Received response status [FAILED] from custom resource. Message returned: database "my-username" does not exist
To fix this, the custom resource should try to use the following for the value of ResourceProperties.Database:
Check to see if cluster.defaultDatabaseName is set and use that value
Use the default engine value of postgres for Postgres
The current implementation only works if credentials is not set on the rds.DatabaseCluster and it defaults to postgres, or if the generated username happens to also be postgres
When creating an
rds.DatabaseCluster
and aRole
with the optioncredentials: rds.Credentials.fromGeneratedSecret("my-username"),
, the Lambda function returns the following error:I believe this is happening because the database config when establishing a client uses
event.ResourceProperties.Database
. However, theRole
custom resource doesn't define aDatabase
property in its outputs to the handler. The default fallback for thepg.Client
object is to use the username. For Aurora Postgres, the default database name ispostgres
and not the username.To fix this, the custom resource should try to use the following for the value of
ResourceProperties.Database
:cluster.defaultDatabaseName
is set and use that valuepostgres
for PostgresThe current implementation only works if
credentials
is not set on therds.DatabaseCluster
and it defaults topostgres
, or if the generated username happens to also bepostgres