diff --git a/packages/@aws-cdk/aws-rds/README.md b/packages/@aws-cdk/aws-rds/README.md index 527a05e72fc7d..cfa53cc0a4abc 100644 --- a/packages/@aws-cdk/aws-rds/README.md +++ b/packages/@aws-cdk/aws-rds/README.md @@ -58,6 +58,21 @@ const instance = new DatabaseInstance(stack, 'Instance', { ``` By default, the master password will be generated and stored in AWS Secrets Manager. +To use the storage auto scaling option of RDS you can specify the maximum allocated storage. +This is the upper limit to which RDS can automatically scale the storage. More info can be found +[here](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling) +Example for max storage configuration: + +```ts +const instance = new DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.ORACLE_SE1, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), + masterUsername: 'syscdk', + vpc, + maxAllocatedStorage: 200 +}); +``` + Use `DatabaseInstanceFromSnapshot` and `DatabaseInstanceReadReplica` to create an instance from snapshot or a source database respectively: @@ -76,6 +91,7 @@ new DatabaseInstanceReadReplica(stack, 'ReadReplica', { vpc }); ``` + Creating a "production" Oracle database instance with option and parameter groups: [example of setting up a production oracle instance](test/integ.instance.lit.ts) diff --git a/packages/@aws-cdk/aws-rds/lib/instance.ts b/packages/@aws-cdk/aws-rds/lib/instance.ts index 03e33c6c18fe1..7971d5bdd55ad 100644 --- a/packages/@aws-cdk/aws-rds/lib/instance.ts +++ b/packages/@aws-cdk/aws-rds/lib/instance.ts @@ -478,6 +478,13 @@ export interface DatabaseInstanceNewProps { * @default RemovalPolicy.Retain */ readonly removalPolicy?: RemovalPolicy + + /** + * Upper limit to which RDS can scale the storage in GiB(Gibibyte). + * @see https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PIOPS.StorageTypes.html#USER_PIOPS.Autoscaling + * @default - No autoscaling of RDS instance + */ + readonly maxAllocatedStorage?: number; } /** @@ -567,7 +574,8 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures), publiclyAccessible: props.vpcPlacement && props.vpcPlacement.subnetType === ec2.SubnetType.PUBLIC, storageType, - vpcSecurityGroups: securityGroups.map(s => s.securityGroupId) + vpcSecurityGroups: securityGroups.map(s => s.securityGroupId), + maxAllocatedStorage: props.maxAllocatedStorage }; } diff --git a/packages/@aws-cdk/aws-rds/test/test.instance.ts b/packages/@aws-cdk/aws-rds/test/test.instance.ts index 2052594ef691f..96c2c7c5bad29 100644 --- a/packages/@aws-cdk/aws-rds/test/test.instance.ts +++ b/packages/@aws-cdk/aws-rds/test/test.instance.ts @@ -716,6 +716,52 @@ export = { }), /timezone property can be configured only for Microsoft SQL Server/); }); + test.done(); + }, + + 'create an instance from snapshot with maximum allocated storage'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + new rds.DatabaseInstanceFromSnapshot(stack, 'Instance', { + snapshotIdentifier: 'my-snapshot', + engine: rds.DatabaseInstanceEngine.POSTGRES, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.LARGE), + vpc, + maxAllocatedStorage: 200 + }); + + expect(stack).to(haveResource('AWS::RDS::DBInstance', { + DBSnapshotIdentifier: 'my-snapshot', + MaxAllocatedStorage: 200 + })); + + test.done(); + }, + + 'create a DB instance with maximum allocated storage'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const vpc = new ec2.Vpc(stack, 'VPC'); + + // WHEN + new rds.DatabaseInstance(stack, 'Instance', { + engine: rds.DatabaseInstanceEngine.MYSQL, + instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL), + masterUsername: 'admin', + vpc, + backupRetention: cdk.Duration.seconds(0), + maxAllocatedStorage: 250 + }); + + // THEN + expect(stack).to(haveResource('AWS::RDS::DBInstance', { + BackupRetentionPeriod: 0, + MaxAllocatedStorage: 250 + })); + test.done(); } };