aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.49k stars 3.84k forks source link

aws_rds: RDS construct cannot create Aurora serverless in Isolated VPC #30827

Closed zmgehlke closed 1 month ago

zmgehlke commented 1 month ago

Describe the bug

I create a VPC using the CDK with isolated networks.

this.vpc = new cdk.aws_ec2.Vpc(this, 'vpc', {
            ipAddresses: cdk.aws_ec2.IpAddresses.cidr('10.0.0.0/16'),
            createInternetGateway: false,
            subnetConfiguration: [
                {
                    name: 'isolated',
                    subnetType: cdk.aws_ec2.SubnetType.PRIVATE_ISOLATED,
                    cidrMask: 24,
                }
            ]
        })

I then create a subnet group:

        const subnetGroup = new cdk.aws_rds.SubnetGroup(this, 'subnets', {
            description: 'ledger-isolated',
            subnetGroupName: 'ledger-isolated',
            removalPolicy: cdk.RemovalPolicy.DESTROY,

            vpc: props.vpc,
            vpcSubnets: {
                subnets: props.vpc.isolatedSubnets
            },
        })

I then create an RDS cluster:

        this.table = new cdk.aws_rds.DatabaseCluster(this, 'ledger', {
            engine: cdk.aws_rds.DatabaseClusterEngine.auroraPostgres({version: cdk.aws_rds.AuroraPostgresEngineVersion.VER_16_2}),
            deletionProtection: false, // TODO: Enable for production.

            serverlessV2MaxCapacity: 2,
            serverlessV2MinCapacity: 0.5,
            vpcSubnets: subnetGroup,

            writer: cdk.aws_rds.ClusterInstance.serverlessV2('writer'),
            readers: [
                cdk.aws_rds.ClusterInstance.serverlessV2('reader')
            ]
        });

I get the following error:

Error: Provide either vpc or instanceProps.vpc, but not both
    at new DatabaseClusterNew [...]
    at new DatabaseCluster [...]

I have tried numerous options on the subnet group and other definitions; no combination of features appears to work.

Expected Behavior

Create RDS serverless cluster in isolated VPC.

Current Behavior

Inscrutable error about defining VPC settings.

Reproduction Steps

See above.

Possible Solution

No response

Additional Information/Context

I'm deeply frustrated that the CDK decided to become "smart" by automating so many important features -- because you took a good product and made it impossible to use, due to the continually malfunctioning automation. RDS wasn't previously impossible to set up, due to the CDK breaking when small customizations were made.

CDK CLI Version

2.148.0

Framework Version

No response

Node.js Version

20.15.1

OS

Ubuntu 22.04

Language

TypeScript

Language Version

No response

Other information

No response

khushail commented 1 month ago

Hey @zmgehlke , thanks for reaching out. Looks like you faced this issue in the latest version.Could you please mention in which CDK version you found it to be correctly working ?

zmgehlke commented 1 month ago

Hi @khushail -- I appreciate your effort investigating this issue, but unfortunately it's been a few years since I've used the RDS construct (since circa 2022) and I no longer know which specific version I was using.

I'm not actually convinced that I'm reporting the correct error, eg if I switch the definition:

    serverlessV2MaxCapacity: 2,
    serverlessV2MinCapacity: 0.5,
    vpc: props.vpc,
    vpcSubnets: subnetGroup,

...then I get a new error where it apparently cannot find the correct subnet entities. My larger complaint is that no variety of options appears to work in even this relatively basic case to accomplish a relatively simple goal -- deploying severless RDS into a VPC.

khushail commented 1 month ago

Hi @zmgehlke , Looks like your issue is quite similar to this one - https://github.com/aws/aws-cdk/issues/29256

The sample code shared here might be what you are looking for- https://github.com/aws/aws-cdk/issues/29256#issuecomment-1965551293

 const cluster = new rds.DatabaseCluster(this, 'Database', {
          engine: rds.DatabaseClusterEngine.auroraMysql({
            version: rds.AuroraMysqlEngineVersion.VER_3_05_2,
          }),
          storageEncrypted: true,
          vpcSubnets: {
            subnetType: ec2.SubnetType.PRIVATE_ISOLATED,
          },
          writer: rds.ClusterInstance.provisioned('instance1', {
            instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.LARGE),
            publiclyAccessible: false,
          }),
          readers: [rds.ClusterInstance.provisioned('instance2', {
            instanceType: ec2.InstanceType.of(ec2.InstanceClass.T3, ec2.InstanceSize.LARGE),
            publiclyAccessible: false,
          })],
          vpc,
        });

Let me know if it works for you

github-actions[bot] commented 1 month ago

This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled.

aws-cdk-automation commented 1 month ago

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.