When specifying a DatabaseCluster for the proxyTarget prop, CloudFormation will not create a dependency on the underlying DB Instances that are provisioned, and so RDS Proxy Target will fail to provision successfully because DB cluster's instances are not yet in an AVAILABLE state.
Use Case
Consider this scenario, where a DatabaseCluster, cluster, is created with DB instances and then referenced in proxyTarget prop:
const cluster = new rds.DatabaseCluster(this, 'cluster', {
defaultDatabaseName: 'default_db',
preferredMaintenanceWindow: "sun:00:00-sun:01:00",
backup: {
preferredWindow: "06:00-08:00",
retention: Duration.days(30)
},
monitoringInterval: Duration.seconds(60),
engine: rds.DatabaseClusterEngine.auroraPostgres({
version: AuroraPostgresEngineVersion.of(
clusterEngine.engineVersion.fullVersion,
clusterEngine.engineVersion.majorVersion
)
}),
instanceProps: {
instanceType: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE3, ec2.InstanceSize.MEDIUM),
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE,
},
vpc: _vpc,
enablePerformanceInsights: true,
securityGroups: [dbSG],
parameterGroup: instanceParmGroup,
},
storageEncrypted: true,
parameterGroup: clusterParmGroup
});
const proxy = new rds.DatabaseProxy(this, 'proxy', {
proxyTarget: rds.ProxyTarget.fromCluster(cluster),
borrowTimeout: cdk.Duration.seconds(30),
maxConnectionsPercent: 50,
secrets: [secret],
vpc: _vpc,
vpcSubnets: {
subnetType: ec2.SubnetType.PRIVATE,
availabilityZones: _vpc.availabilityZones
},
securityGroups: [dbSG],
dbProxyName: 'Test'
});
Deploying this results in an error:
> 12/16 | 10:13:32 PM | CREATE_FAILED | AWS::RDS::DBProxyTargetGroup | proxy/ProxyTargetGroup (proxyProxyTargetGroupB8910A04) DB Instance ut19fzdsrvpofm1 is in an unsupported state - CREATING, needs
to be in [AVAILABLE, MODIFYING, BACKING_UP] (Service: AmazonRDS; Status Code: 400; Error Code: InvalidDBInstanceState; Request ID: x; Proxy: null)
During synthesis, DBProxy and DBProxyTargetGroup begin to provision after DBCluster is created, but before DBInstances have been provisioned. Adding this line resolves this:
proxy.node.addDependency(cluster);
Synthesized result with DependsOn:
proxyProxyTargetGroupC81A1D54:
Type: AWS::RDS::DBProxyTargetGroup
Properties:
DBProxyName:
Ref: proxy3A1DA9C7
TargetGroupName: default
ConnectionPoolConfigurationInfo:
ConnectionBorrowTimeout: 30
MaxConnectionsPercent: 50
DBClusterIdentifiers:
- Ref: cluster611F8AFF
DependsOn:
- clusterInstance183584D40
- clusterInstance23D1AD8B2
- clusterMonitoringRole0D1DE37E
- cluster611F8AFF
- clusterSecretAttachment69BFCEC4
- clusterSecretE349B730
- clusterSubnets81E3593F
Proposed Solution
Ideally, logic in DataBaseProxy would detect this dependency and automatically add the dependency. I suspect this logic could be added in the bind function of proxy.ts but am not quite sure.
Other
This is a 🚀 Feature Request
When specifying a
DatabaseClusterfor theproxyTargetprop, CloudFormation will not create a dependency on the underlying DB Instances that are provisioned, and so RDS Proxy Target will fail to provision successfully because DB cluster's instances are not yet in anAVAILABLEstate.Use Case
Consider this scenario, where a DatabaseCluster,
cluster, is created with DB instances and then referenced inproxyTargetprop:Deploying this results in an error:
During synthesis, DBProxy and DBProxyTargetGroup begin to provision after
DBClusteris created, but beforeDBInstanceshave been provisioned. Adding this line resolves this:Synthesized result with
DependsOn:Proposed Solution
Ideally, logic in
DataBaseProxywould detect this dependency and automatically add the dependency. I suspect this logic could be added in thebindfunction of proxy.ts but am not quite sure.Other
This is a 🚀 Feature Request