From 3d0dd511d8aa0e21d5ca5768b4c648c9c09f20c2 Mon Sep 17 00:00:00 2001 From: John Russell Date: Wed, 6 Mar 2024 13:37:37 -0800 Subject: [PATCH] Set up CDK setup path to use Serverless v2 instead of Serverless v1 Create DatabaseCluster instead of ServerlessCluster. Still likely needs some more to make an instance associated with the DatabaseCluster - that wasn't needed in Serverless v1. And then the instance needs to have instance class 'db.serverless' instead of one of the provisioned instance classes like db.t4g.medium. The last piece would be to include the 'enable Data API' / 'enable HTTP endpoint' flag. However, that doesn't seem to be available yet for DatabaseCluster in the CDK. There is an open pull request to add it: https://github.com/aws/aws-cdk/pull/29338 So I think the changes to setup.ts can't be 100% finalized until that pull request is merged. Although I was able to test the updated Python examples by setting up resources using the CloudFormation setup.yaml and/or 'python library_demo.py deploy_database'. --- resources/cdk/aurora_serverless_app/setup.ts | 21 +++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/resources/cdk/aurora_serverless_app/setup.ts b/resources/cdk/aurora_serverless_app/setup.ts index 75cec12020d..d36f3b6eba0 100644 --- a/resources/cdk/aurora_serverless_app/setup.ts +++ b/resources/cdk/aurora_serverless_app/setup.ts @@ -14,7 +14,7 @@ import 'source-map-support/register'; import {Construct} from "constructs"; import {App, CfnOutput, Duration, Stack, StackProps} from 'aws-cdk-lib'; import {Secret} from 'aws-cdk-lib/aws-secretsmanager'; -import {Credentials, DatabaseClusterEngine, ServerlessCluster} from "aws-cdk-lib/aws-rds"; +import {Credentials, DatabaseClusterEngine, DatabaseCluster, DatabaseInstance, ServerlessCluster} from "aws-cdk-lib/aws-rds"; export class SetupStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { @@ -33,18 +33,29 @@ export class SetupStack extends Stack { }); const dbname = 'auroraappdb' - const cluster: ServerlessCluster = new ServerlessCluster(this, 'doc-example-aurora-app-cluster', { - engine: DatabaseClusterEngine.AURORA_MYSQL, + +// const cluster: ServerlessCluster = new ServerlessCluster(this, 'doc-example-aurora-app-cluster', { +// engine: DatabaseClusterEngine.AURORA_MYSQL, +// defaultDatabaseName: dbname, +// enableDataApi: true, +// scaling: {autoPause: Duration.minutes(0)}, +// credentials: Credentials.fromSecret(secret, username) +// }) + + const cluster: DatabaseCluster = new DatabaseCluster(this, 'doc-example-aurora-app-cluster', { + engine: DatabaseClusterEngine.AURORA_POSTGRESQL, defaultDatabaseName: dbname, enableDataApi: true, - scaling: {autoPause: Duration.minutes(0)}, + serverlessV2MinCapacity: 0.5, + serverlessV2MaxCapacity: 8, credentials: Credentials.fromSecret(secret, username) }) // Create outputs from the stack. These values are required by Amazon Relational // Database Service (Amazon RDS) Data Service to run SQL statements on the cluster. new CfnOutput(this, 'SecretArn', {value: secret.secretArn}) - new CfnOutput(this, 'ClusterArn', {value: cluster.clusterArn}) +// new CfnOutput(this, 'ClusterArn', {value: cluster.clusterArn}) + new CfnOutput(this, 'ClusterArn', {value: cluster.clusterResourceIdentifier}) new CfnOutput(this, 'DbName', {value: dbname}) } }