Skip to content

[rds] Automatic addDependency for DatabaseProxy.proxyTarget to ensure DB Instances are available #11311

@senorkrabs

Description

@senorkrabs

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

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-rdsRelated to Amazon Relational Databaseeffort/smallSmall work item – less than a day of effortfeature-requestA feature should be added or improved.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions