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.72k stars 3.94k forks source link

(rds): support for Aurora Serverless V2 #20197

Closed rpbarnes closed 1 year ago

rpbarnes commented 2 years ago

Describe the feature

Please like the original post instead of leaving a +1 comment.

Add CDK support for aurora serverless v2 ideally via the ServerlessCluster construct.

edit there's a few solutions using base cloud formation constructs in the comments. Please see those for a work around.

Currently deploying a Serverless V2 instance via cdk doesn't seem possible.

I've got this far

        enum ServerlessInstanceType {
            SERVERLESS = 'serverless',
        }
        type CustomInstanceType = ServerlessInstanceType | ec2.InstanceType;
        const CustomInstanceType = {
            ...ServerlessInstanceType,
            ...ec2.InstanceType,
        };

        this.serverlessCluster = new DatabaseCluster(
            this,
            'ServerlessClusterV2',
            {
                engine: DatabaseClusterEngine.auroraMysql({
                    version: AuroraMysqlEngineVersion.of(
                        '8.0.mysql_aurora.3.02.0'
                    ), // The new minor version of Database Engine.
                }),
                storageEncrypted: true,
                iamAuthentication: true,
                parameterGroup: ParameterGroup.fromParameterGroupName(
                    this,
                    'rdsClusterPrameterGroup',
                    'default.aurora-mysql8.0'
                ),
                storageEncryptionKey: new Key(this, 'dbEncryptionKey'),
                instanceProps: {
                    instanceType:
                        CustomInstanceType.SERVERLESS as unknown as InstanceType,
                    vpc: props.vpc,
                    vpcSubnets: {
                        subnetType: SubnetType.PRIVATE_ISOLATED,
                    },
                },
            }
        );

but I keep running into this error

Set the Serverless v2 scaling configuration on the parent DB cluster before creating a Serverless v2 DB instance.

Which I can't figure out a way around.

Use Case

Need to create a DB via CDK. I want to use Serverless V2 because of the support for mysql 8.0.

Proposed Solution

No response

Other Information

No response

Acknowledgements

CDK version used

2.15.0

Environment details (OS name and version, etc.)

mac OS X

jvlch commented 2 years ago

I found a workaround using a custom resource, uses addDependency on instances to a custom resource that sets the min/max capacity settings

enum ServerlessInstanceType {
  SERVERLESS = 'serverless',
}

type CustomInstanceType = ServerlessInstanceType | ec2.InstanceType;

const CustomInstanceType = { ...ServerlessInstanceType, ...ec2.InstanceType };

const dbClusterInstanceCount: number = 1

const dbCluster = new rds.DatabaseCluster(this, 'DbCluster', {
  engine: rds.DatabaseClusterEngine.auroraPostgres({
    version: rds.AuroraPostgresEngineVersion.VER_13_6,
  }),
  instances: dbClusterInstanceCount,
  instanceProps: {
    vpc: vpc,
    instanceType: CustomInstanceType.SERVERLESS as unknown as ec2.InstanceType,
    autoMinorVersionUpgrade: false,
    publiclyAccessible: false,
    securityGroups: [
      dbSecurityGroup,
    ],
    vpcSubnets: {
      subnets: [vpc.isolatedSubnets[0], vpc.isolatedSubnets[1], vpc.isolatedSubnets[2]]
    },
  },
  credentials: rds.Credentials.fromSecret(dbAdminSecret),
  backup: {
    retention: cdk.Duration.days(7),
    preferredWindow: '08:00-09:00'
  },
  port: 5432,
  cloudwatchLogsExports: ["postgresql"],
  cloudwatchLogsRetention: logs.RetentionDays.SIX_MONTHS,
  subnetGroup: dbSubnetGroup,
  storageEncrypted: true,
  storageEncryptionKey: dbKey,
})

const serverlessV2ScalingConfiguration = {
  MinCapacity: 0.5,
  MaxCapacity: 16,
}

const dbScalingConfigure = new cr.AwsCustomResource(this, 'DbScalingConfigure', {
  onCreate: {
    service: "RDS",
    action: "modifyDBCluster",
    parameters: {
      DBClusterIdentifier: dbCluster.clusterIdentifier,
      ServerlessV2ScalingConfiguration: serverlessV2ScalingConfiguration,
    },
    physicalResourceId: cr.PhysicalResourceId.of(dbCluster.clusterIdentifier)
  },
  onUpdate: {
    service: "RDS",
    action: "modifyDBCluster",
    parameters: {
      DBClusterIdentifier: dbCluster.clusterIdentifier,
      ServerlessV2ScalingConfiguration: serverlessV2ScalingConfiguration,
    },
    physicalResourceId: cr.PhysicalResourceId.of(dbCluster.clusterIdentifier)
  },
  policy: cr.AwsCustomResourcePolicy.fromSdkCalls({
    resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE,
  }),
})

const cfnDbCluster = dbCluster.node.defaultChild as rds.CfnDBCluster
const dbScalingConfigureTarget = dbScalingConfigure.node.findChild("Resource").node.defaultChild as cdk.CfnResource

cfnDbCluster.addPropertyOverride("EngineMode", "provisioned")
dbScalingConfigure.node.addDependency(cfnDbCluster)

for (let i = 1 ; i <= dbClusterInstanceCount ; i++) { 
  (dbCluster.node.findChild(`Instance${i}`) as rds.CfnDBInstance).addDependsOn(dbScalingConfigureTarget)
}
rpbarnes commented 2 years ago

Wo that's cool.

I'll give that a try. Just curious though... Is AWS planning on adding Aurora Serverless V2 setup as proper cdk constructs? I'm happy to wait a bit if I can get the proper thing instead of moving forward with the workaround.

skinny85 commented 2 years ago

Yes, this is definitely on our roadmap. Not sure when we're going to get to it though - leaving +1s on the issue will definitely help us prioritize.

We also encourage community contributions. Our "Contributing" guide: https://github.com/aws/aws-cdk/blob/master/CONTRIBUTING.md.

Thanks, Adam

fourgates commented 2 years ago

+1

rpbarnes commented 2 years ago

+1

Sent from my iPhone

On May 4, 2022, at 7:47 PM, Phillip Ninan @.***> wrote:

ο»Ώ +1

β€” Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

shobhit-ec11 commented 2 years ago

+1

carlsonorozco commented 2 years ago

+1

owenmorgan commented 2 years ago

+1

valentin-nasta commented 2 years ago

+1

jvlch commented 2 years ago

+1

alexandrustf commented 2 years ago

+1

Anonyfox commented 2 years ago

+1

code11octo commented 2 years ago

+1

therockstorm commented 2 years ago

I'm happy to see this is such a popular request as I want it too! Could we please πŸ‘ the original description instead of adding +1 comments? I imagine there are many people subscribed to this issue and each of these comments notify all of them. Additionally, adding a πŸ‘ allows the CDK team to sort issues by that reaction to inform priority.

RubysDad commented 2 years ago

+1

Harper04 commented 2 years ago

+1

mrgum commented 2 years ago

+1

JonHawke commented 2 years ago

+1

dillon-litify commented 2 years ago

+1

avibait commented 2 years ago

+1

randerrocks commented 2 years ago

+1

github-actions[bot] commented 2 years ago

This issue has received a significant amount of attention so we are automatically upgrading its priority. A member of the community will see the re-prioritization and provide an update on the issue.

matart15 commented 2 years ago

+1

tomereli commented 2 years ago

+1

Lettly commented 2 years ago

+1 it's necessary

cbake6807 commented 2 years ago

+1 for CDK!

michaelguren commented 2 years ago

+1

petyots commented 2 years ago

+1

maikebertpsc commented 2 years ago

+1

mercanil commented 2 years ago

+1

ClaudenirFreitas commented 2 years ago

+1

jamescummins commented 2 years ago

+100

rsung-deepwatch commented 2 years ago

+1

Pingid commented 2 years ago

+1

prasadgunasekaran commented 2 years ago

+1

kaizencc commented 2 years ago

Hey all, thanks for your help adding πŸ‘'s to the original issue description. That is how we track engagement, and how the github action picked up this issue as a candidate for higher priority. The "+1" comments don't factor into that, unnecessarily notify people, and clutter the discussion that has a solid workaround idea near the top: https://github.com/aws/aws-cdk/issues/20197#issuecomment-1117555047

Clearly this is something people are looking forward to so I'm keeping this as p1. That means it's on our roadmap, but currently, we don't have anyone working on this. Someone from the CDK team will update when they pick this up. Additionally, if someone from the community is interested in contributing this, please let us know and we'll work with you. As this is a larger change, I'd prefer if we went through a couple of API iterations before any PRs get submitted.

Feel free to continue to πŸ‘ the issue description.

kaizencc commented 2 years ago

Looks like this is not available in cloudformation yet. The CDK depends on cloudformation, so we need to wait until cfn officially supports this feature.

With that in mind, it would be far more effective to add your πŸ‘ to this issue as well: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/1150

dovidkopel commented 2 years ago

+1

pahud commented 2 years ago

Wondering if someone from the community would love to pick up this and submit a PR? Is there any blocker that stops you from making a PR? Would love to remove the blocker and help the community for PR submission.

valentin-nasta commented 2 years ago

@pahud from what I understood the cloudformation part is blocker and must be fixed/implemented first.

adrnola commented 2 years ago

+1

jonatan-blossom commented 2 years ago

+1

fourgates commented 2 years ago

FWIW -- I have 3 clusters provisioned via the CDK. As per the docs, I upgraded one of them to Postgres 13.6 and was able to add a serverless v2 reader. I used the same procedure on the 2nd cluster and I'm getting the same error in the console.

Set the Serverless v2 scaling configuration on the parent DB cluster before creating a Serverless v2 DB instance.

I see this setting In the parent DB cluster of the successful upgrade, but not the 2nd cluster I am trying to upgrade. Very frustrating. image image

UPDATE:

This was a fix via the was CLI.

brifiction commented 2 years ago

+1

galsasi1989 commented 2 years ago

+1

liadkaradi commented 2 years ago

+1

avnersch commented 2 years ago

+1

rsilvestre commented 2 years ago

+100

mickymots commented 2 years ago

+500

murrayk commented 2 years ago

+1