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

AWS::RDS::DBCluster ignores DBSubnetGroupName property when creating a clone #336

Closed
rlister opened this issue Jan 10, 2020 · 17 comments · Fixed by aws-cloudformation/aws-cloudformation-resource-providers-rds#329
Labels
database RDS, DynamoDB, ElastiCache, Neptune, Amazon Redshift, Amazon QLDB, Amazon DocumentDB

Comments

@rlister
Copy link

rlister commented Jan 10, 2020

  1. AWS::RDS::DBCluster

  2. Cloudformation now supports RDS clones, courtesy of SourceDBClusterIdentifier and RestoreType properties (see AWS::RDS (Aurora Cloning Support) #18). The cluster creates correctly, with the exception of property DBSubnetGroupName, which appears to be ignored. Rather than using the configured value, the resource silently defaults to using default as a value.

  3. Expected behavior: Cloudformation should use property DBSubnetGroupName.

  4. I am testing with the following resource template:

"DbCluster": {
  "Type": "AWS::RDS::DBCluster",
  "DependsOn": [
    "SubnetGroup",
    "DbClusterParamGroup"
  ],
  "DeletionPolicy": "Delete",
  "Properties": {
    "SourceDBClusterIdentifier": {
      "Ref": "SourceCluster"
    },
    "RestoreType": "copy-on-write",
    "DBClusterParameterGroupName": {
      "Ref": "DbClusterParamGroup"
    },
    "DBSubnetGroupName": {
      "Ref": "SubnetGroup"
    },
    "UseLatestRestorableTime": true,
    "VpcSecurityGroupIds": [
      {
        "Fn::ImportValue": {
          "Fn::Sub": [
            "${vpc}-SgDb",
            {
            }
          ]
        }
      }
    ]
  }
}
  1. Links to existing API doc: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html

  2. Category tag (optional) -> Database

  3. Any additional context: I can create a working cluster using both AWS CLI and ruby-sdk with the same set of properties, and the subnet group is set correctly.

@TheDanBlanco TheDanBlanco added the database RDS, DynamoDB, ElastiCache, Neptune, Amazon Redshift, Amazon QLDB, Amazon DocumentDB label Jan 21, 2020
@kderholt
Copy link

Will this be fixed?

@d2kx
Copy link

d2kx commented Apr 30, 2020

Ran into the same issue today. Great addition to the RDS CloudFormaton set otherwise ❤

@piotrtpay
Copy link

Ran into the same issue, but I'm not actually getting Internal Failure, which I'm able to reproduce using the API ( when DBSubnetGroupName is specified, there's no issue, but it's not being passed from CloudFormation, and if I leave it empty, I get the same error )

@kderholt
Copy link

kderholt commented Sep 9, 2020

Still nothin from AWS on this ? This should just be fixed, its an annoying bug which would be much appreciated if fixed!

@piotrtpay
Copy link

@kderholt

A workaround I was able to use was to create a custom resource lambda, to which I pass the DB name via CDK, and which uses boto3 to create the DB clone. By using crhelper you can make it also delete the DB on stack deletion. The lambda is created during the CDK run. That's actually what AWS themselves do in some cases ( ECR stack uses a custom resource lambda for ECR creation for example )

@dillonbrowne
Copy link

Is there another workaround besides a lambda?

@kderholt
Copy link

I'm amazed that this is not yet fixed. They should remove it from the cloudformation api/function as it does not seem like a priority for AWS. It's been like this for almost a year now.
To answer your question, we used sdk and just "wait" for it to clone finish (stateful wait, instead of the stateless (from cf or lambda like piotrtpay suggest)).

@sureshc
Copy link

sureshc commented Feb 3, 2021

Would love to see a resolution to this issue as well. Currently we're programmatically creating / deleting the Resources needed to clone a cluster within the same non-default VPC. We' prefer to use CloudFormation.

@mikey-
Copy link

mikey- commented Apr 21, 2021

I came across this issue(and #18) today; I wonder if this issue occurs due to the fact that dbSubnetGroupName(model.getDBSubnetGroupName()) is not included in one of the RDS resource provider's translator function:

image

These functions seem to be responsible for creating API requests from ResourceModels, including the relevant properties and excluding the irrelevant properties. Unfortunately, it seems to me that this is the DBSubnetGroupName property has been mistakenly "ignored", and why CloudFormation always creates cloned clusters in the default VPC and subnet group.

Anyway, I hope that this helps :)

@mikey-
Copy link

mikey- commented Apr 24, 2021

Update: I made a similar comment to the one I made above, but on the internal issue which tracks this one - and I've received a reply saying

this is right. we should include the field. @osdrv is the primary engineer and will be able to address

So we can look forward to that :)

@chucksellick
Copy link

Unbelievable, I wasted most of today trying to get a cloned db instance, doesn't help that the error I saw was completely unfathomable and it additionally takes about 30 minutes each run to find out that my template has failed again. Well thank you for putting the information here, at least I eventually found out this was an AWS bug.

For reference in case anyone else is searching for the same error, the specific error this triggered for me was:

Subnet group <DBSubnetGroupName> is different from subnet group of cluster <DBClusterIdentifier>

Presumably this is because the cluster subnet group name is silently changing to default, therefore it now conflicts with the instance I was also creating which does honour the subnet group name.

Not the first time I've wasted significant chunks of my day chasing around an issue where Cloudformation just isn't doing what it should be doing. Would be nice if there was a little more response from AWS on some of these issues, I've seen some other tickets around this that are just closed without comment.

Well I guess for now I just clone the DB by hand and hope this gets fixed some time this decade.

@cfn-github-issues-bot cfn-github-issues-bot added this to Researching in coverage-roadmap Sep 7, 2021
@fschroder-slyp
Copy link

From my testing I think the security group property is being ignored too. Referenced code above seems to confirm this.

As part of debugging this I deleted default resources and got error messages like:

  • No default subnet detected in VPC
  • The VPC vpc-xxxxxx associated with the default subnet group does not exist. Please delete the default subnet group or specify another subnet group.

@mikey-
Copy link

mikey- commented Nov 7, 2021

@fschroder-slyp nice pickup Fed! Yeah, looks like the translator function needs to include vpcSecurityGroupIds(model.getVpcSecurityGroupIds()).

@scottiemc7
Copy link

I believe EngineMode is similarly being ignored when cloning. I was trying to create a provisioned clone of a serverless database and ran across this issue. Works fine from the CLI, but CF is 🤷‍♂️

@spg
Copy link

spg commented Apr 28, 2022

I experience the same issue while deploying a stack with the CDK (Version 2.20.0). Here is the message in the Cloudformation events:

Subnet group mysubnetgroup is different from subnet group of cluster my-stack-cluster-1o9ycaXXXXX (Service: AmazonRDS; Status Code: 400; Error Code: InvalidParameterCombination; Request ID: 39ffaf1b-0a2c-4334-80ce-XXXXXXXX; Proxy: null)

Here is the CDK stack:

import * as cdk from 'aws-cdk-lib'
import ec2 from 'aws-cdk-lib/aws-ec2'
import rds from 'aws-cdk-lib/aws-rds'
import { Construct } from 'constructs'

interface StackProps extends cdk.StackProps {
  sourceDbClusterIdentifier: string
}

export class MyStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props: StackProps) {
    super(scope, id, props)

    const sourceDbClusterIdentifier = 'cloud-database-postgresdbdbclusterb3fd976e-XXXXXXXX'
    const engine = 'aurora-postgresql'
    const engineVersion = '13.4'

    const subnetGroup = new rds.CfnDBSubnetGroup(this, 'subnetgroup', {
      dbSubnetGroupDescription: 'for testing',
      subnetIds: ['subnet-0dfb6be3236XXXX', 'subnet-00a09a796fe8XXXXX', 'subnet-0b83fcabffXXXXXX'],
      dbSubnetGroupName: 'mysubnetgroup',
    })

    const securityGroup = new ec2.CfnSecurityGroup(this, 'id', {
      vpcId: 'vpc-0c6497d314XXXXXX'
      groupDescription: 'testing',
    })

    const cluster = new rds.CfnDBCluster(this, 'Cluster', {
      engine,
      useLatestRestorableTime: true,
      sourceDbClusterIdentifier,
      engineVersion,
      dbSubnetGroupName: subnetGroup.ref,
      vpcSecurityGroupIds: [securityGroup.ref],
    })

    new rds.CfnDBInstance(this, 'instance', {
      dbInstanceClass: 'db.r5.large',
      dbClusterIdentifier: cluster.ref,
      engine,
      engineVersion,
      publiclyAccessible: true,
      dbSubnetGroupName: subnetGroup.ref,
    })

    new cdk.CfnOutput(this, 'ClusterEndpointAddress', { value: cluster.attrEndpointAddress })
    new cdk.CfnOutput(this, 'ClusterEndpointPort', { value: cluster.attrEndpointPort })
  }
}

osdrv pushed a commit to aws-cloudformation/aws-cloudformation-resource-providers-rds that referenced this issue Oct 6, 2022
…329)

This commit modifies RestoreDBClusterToPointInTime request
construction. In particular, VPCSecurityGroupIds parameter is being
passed from the desired resource state. In this case one can restore a
customer with a reference to the same security group set as the original
cluster.

Fixes #15.
Fixes aws-cloudformation/cloudformation-coverage-roadmap#336.

Signed-off-by: Oleg Sidorov <sidorovo@amazon.com>
@moataz-mhmd
Copy link

Addressed in aws-cloudformation/aws-cloudformation-resource-providers-rds#329. Change deployed globally.

@rlister
Copy link
Author

rlister commented Nov 16, 2022

This works now. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database RDS, DynamoDB, ElastiCache, Neptune, Amazon Redshift, Amazon QLDB, Amazon DocumentDB
Projects
coverage-roadmap
  
Researching
Development

Successfully merging a pull request may close this issue.