@@ -104,6 +104,18 @@ export class LogType {
104104 public constructor ( public readonly value : string ) { }
105105}
106106
107+ export interface ServerlessScalingConfiguration {
108+ /**
109+ * Minimum NCU capacity (min value 1)
110+ */
111+ readonly minCapacity : number ;
112+
113+ /**
114+ * Maximum NCU capacity (min value 2.5 - max value 128)
115+ */
116+ readonly maxCapacity : number ;
117+ }
118+
107119/**
108120 * Properties for a new database cluster
109121 */
@@ -297,6 +309,14 @@ export interface DatabaseClusterProps {
297309 * @default - a new role is created.
298310 */
299311 readonly cloudwatchLogsRetentionRole ?: iam . IRole ;
312+
313+ /**
314+ * Specify minimum and maximum NCUs capacity for a serverless cluster.
315+ * See https://docs.aws.amazon.com/neptune/latest/userguide/neptune-serverless-capacity-scaling.html
316+ *
317+ * @default - required if instanceType is db.serverless
318+ */
319+ readonly serverlessScalingConfiguration ?: ServerlessScalingConfiguration ;
300320}
301321
302322/**
@@ -565,6 +585,12 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
565585
566586 this . enableIamAuthentication = props . iamAuthentication ;
567587
588+ if ( props . instanceType === InstanceType . SERVERLESS && ! props . serverlessScalingConfiguration ) {
589+ throw new Error ( 'You need to specify a serverless scaling configuration with a db.serverless instance type.' ) ;
590+ }
591+
592+ this . validateServerlessScalingConfiguration ( props . serverlessScalingConfiguration ) ;
593+
568594 // Create the Neptune cluster
569595 const cluster = new CfnDBCluster ( this , 'Resource' , {
570596 // Basic
@@ -585,6 +611,7 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
585611 // CloudWatch Logs exports
586612 enableCloudwatchLogsExports : props . cloudwatchLogsExports ?. map ( logType => logType . value ) ,
587613 storageEncrypted,
614+ serverlessScalingConfiguration : props . serverlessScalingConfiguration ,
588615 } ) ;
589616
590617 cluster . applyRemovalPolicy ( props . removalPolicy , {
@@ -649,4 +676,18 @@ export class DatabaseCluster extends DatabaseClusterBase implements IDatabaseClu
649676 securityGroups : securityGroups ,
650677 } ) ;
651678 }
679+
680+ private validateServerlessScalingConfiguration ( serverlessScalingConfiguration ?: ServerlessScalingConfiguration ) {
681+ if ( ! serverlessScalingConfiguration ) return ;
682+ if ( serverlessScalingConfiguration . minCapacity < 1 ) {
683+ throw new Error ( `ServerlessScalingConfiguration minCapacity must be greater or equal than 1, received ${ serverlessScalingConfiguration . minCapacity } ` ) ;
684+ }
685+ if ( serverlessScalingConfiguration . maxCapacity < 2.5 || serverlessScalingConfiguration . maxCapacity > 128 ) {
686+ throw new Error ( `ServerlessScalingConfiguration maxCapacity must be between 2.5 and 128, reveived ${ serverlessScalingConfiguration . maxCapacity } ` ) ;
687+ }
688+ if ( serverlessScalingConfiguration . minCapacity >= serverlessScalingConfiguration . maxCapacity ) {
689+ throw new Error ( `ServerlessScalingConfiguration minCapacity ${ serverlessScalingConfiguration . minCapacity } ` +
690+ `must be less than serverlessScalingConfiguration maxCapacity ${ serverlessScalingConfiguration . maxCapacity } ` ) ;
691+ }
692+ }
652693}
0 commit comments