Closed rpbarnes closed 1 year 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)
}
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.
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
+1
+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.
+1
+1
+1
+1
+1
+1
+1
+1
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.
+1
+1
+1
+1
+1
+1
+1
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.
+1
+1
+1 it's necessary
+1 for CDK!
+1
+1
+1
+1
+1
+100
+1
+1
+1
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.
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
+1
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.
@pahud from what I understood the cloudformation part is blocker and must be fixed/implemented first.
+1
+1
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.
UPDATE:
This was a fix via the was CLI.
+1
+1
+1
+1
+100
+500
+1
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
but I keep running into this error
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