Skip to content

Commit

Permalink
Set up CDK setup path to use Serverless v2 instead of Serverless v1
Browse files Browse the repository at this point in the history
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:

aws/aws-cdk#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'.
  • Loading branch information
max-webster committed Mar 6, 2024
1 parent d6e29e9 commit 3d0dd51
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions resources/cdk/aurora_serverless_app/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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})
}
}
Expand Down

0 comments on commit 3d0dd51

Please # to comment.