Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
2 tasks
senorkrabs opened this issue Nov 5, 2020 · 2 comments · Fixed by #12237
Closed
2 tasks
Assignees
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1

Comments

@senorkrabs
Copy link

senorkrabs commented Nov 5, 2020

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

@senorkrabs senorkrabs added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 5, 2020
@github-actions github-actions bot added the @aws-cdk/aws-rds Related to Amazon Relational Database label Nov 5, 2020
@skinny85
Copy link
Contributor

skinny85 commented Dec 5, 2020

Thanks for opening the issue @senorkrabs . Any chance of opening us a PR adding this fix? Should be a relatively simple change in proxy.ts. Our Contributing guide: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md .

Thanks,
Adam

@skinny85 skinny85 added effort/small Small work item – less than a day of effort p1 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 5, 2020
saudkhanzada pushed a commit to saudkhanzada/aws-cdk that referenced this issue Dec 26, 2020
saudkhanzada pushed a commit to saudkhanzada/aws-cdk that referenced this issue Dec 26, 2020
saudkhanzada pushed a commit to saudkhanzada/aws-cdk that referenced this issue Dec 26, 2020
@mergify mergify bot closed this as completed in #12237 Jan 4, 2021
mergify bot pushed a commit that referenced this issue Jan 4, 2021
…12237)

availability while creating the proxy

Fixes: #11311


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

github-actions bot commented Jan 4, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

flochaz pushed a commit to flochaz/aws-cdk that referenced this issue Jan 5, 2021
…ws#12237)

availability while creating the proxy

Fixes: aws#11311


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-rds Related to Amazon Relational Database effort/small Small work item – less than a day of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants