berenddeboer / cdk-rds-sql

A CDK construct that allows creating roles and databases an on Aurora Serverless Postgresql cluster.
Apache License 2.0
23 stars 11 forks source link

Circular dependency when working across stacks #20

Closed ww-daniel-mora closed 5 months ago

ww-daniel-mora commented 6 months ago

Currently to use this library all initialization code must be in the same stack as the database creation. This is problematic as errors in initialization leave the entire database in a ROLLBACK state which (as far as I can tell so far) requires that the database be deleted.

Attempting to move initialization code to a different stack results in cdk circular reference errors where I believe this is the offending line:

https://github.com/berenddeboer/cdk-rds-sql/blob/2791bb9628ea18673153da44dbd791d3062d3082/src/provider.ts#L88

The initialization stack depends on the database but the above line causes the database to also depend on initialization.

As discussed in this SO: https://stackoverflow.com/questions/77407725/aws-cdk-non-obvious-cyclic-dependency-between-fargate-task-and-rds

Which references the EC2 docs which state:

but if there are existing dependencies (i.e. stack1 already depends on stack2), then it is important to make the connection in the dependent stack (i.e. stack1).

So we should be able to achieve the same effect by making making the call on the handler rather that on the database