Skip to content

Commit fcc79bf

Browse files
committed
feat(rds): configure maxAllocatedStorage for rds fixes #6666
1 parent 0399ffc commit fcc79bf

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

packages/@aws-cdk/aws-rds/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ new DatabaseInstanceReadReplica(stack, 'ReadReplica', {
7676
vpc
7777
});
7878
```
79+
80+
To use the storage auto scaling option of RDS you can specify the maximum allocated storage.
81+
This is the upper limit to which RDS can automatically scale the storage. More info can be found
82+
[here](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-rds-database-instance.html#cfn-rds-dbinstance-maxallocatedstorage)
83+
Example for max storage configuration:
84+
```ts
85+
const instance = new DatabaseInstance(stack, 'Instance', {
86+
engine: rds.DatabaseInstanceEngine.ORACLE_SE1,
87+
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
88+
masterUsername: 'syscdk',
89+
vpc,
90+
maxAllocatedStorage: 200
91+
});
92+
```
93+
7994
Creating a "production" Oracle database instance with option and parameter groups:
8095

8196
[example of setting up a production oracle instance](test/integ.instance.lit.ts)

packages/@aws-cdk/aws-rds/lib/instance.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,12 @@ export interface DatabaseInstanceNewProps {
478478
* @default RemovalPolicy.Retain
479479
*/
480480
readonly removalPolicy?: RemovalPolicy
481+
482+
/**
483+
* Upper limit to which RDS can scale the storage
484+
* @default - No default value
485+
*/
486+
readonly maxAllocatedStorage?: number;
481487
}
482488

483489
/**
@@ -567,7 +573,8 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
567573
processorFeatures: props.processorFeatures && renderProcessorFeatures(props.processorFeatures),
568574
publiclyAccessible: props.vpcPlacement && props.vpcPlacement.subnetType === ec2.SubnetType.PUBLIC,
569575
storageType,
570-
vpcSecurityGroups: securityGroups.map(s => s.securityGroupId)
576+
vpcSecurityGroups: securityGroups.map(s => s.securityGroupId),
577+
maxAllocatedStorage: props.maxAllocatedStorage
571578
};
572579
}
573580

packages/@aws-cdk/aws-rds/test/test.instance.ts

+46
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,52 @@ export = {
716716
}), /timezone property can be configured only for Microsoft SQL Server/);
717717
});
718718

719+
test.done();
720+
},
721+
722+
'create an instance from snapshot with maxiumum allocated storage'(test: Test) {
723+
// GIVEN
724+
const stack = new cdk.Stack();
725+
const vpc = new ec2.Vpc(stack, 'VPC');
726+
727+
// WHEN
728+
new rds.DatabaseInstanceFromSnapshot(stack, 'Instance', {
729+
snapshotIdentifier: 'my-snapshot',
730+
engine: rds.DatabaseInstanceEngine.POSTGRES,
731+
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.LARGE),
732+
vpc,
733+
maxAllocatedStorage: 200
734+
});
735+
736+
expect(stack).to(haveResource('AWS::RDS::DBInstance', {
737+
DBSnapshotIdentifier: 'my-snapshot',
738+
MaxAllocatedStorage: 200
739+
}));
740+
741+
test.done();
742+
},
743+
744+
'create a DB instance with maxiumum allocated storage'(test: Test) {
745+
// GIVEN
746+
const stack = new cdk.Stack();
747+
const vpc = new ec2.Vpc(stack, 'VPC');
748+
749+
// WHEN
750+
new rds.DatabaseInstance(stack, 'Instance', {
751+
engine: rds.DatabaseInstanceEngine.MYSQL,
752+
instanceClass: ec2.InstanceType.of(ec2.InstanceClass.BURSTABLE2, ec2.InstanceSize.SMALL),
753+
masterUsername: 'admin',
754+
vpc,
755+
backupRetention: cdk.Duration.seconds(0),
756+
maxAllocatedStorage: 250
757+
});
758+
759+
// THEN
760+
expect(stack).to(haveResource('AWS::RDS::DBInstance', {
761+
BackupRetentionPeriod: 0,
762+
MaxAllocatedStorage: 250
763+
}));
764+
719765
test.done();
720766
}
721767
};

0 commit comments

Comments
 (0)