Skip to content

Commit 89a7365

Browse files
authored
feat(rds): dual-stack mode support (#22596)
This PR adds dual-stack mode support to RDS instances and clusters. ### Aurora - Working with a DB cluster in a VPC https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html - CloudFormation AWS::RDS::DBCluster https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbcluster.html#cfn-rds-dbcluster-networktype ```ts declare const vpc: ec2.Vpc; // VPC and subnets must have IPv6 CIDR blocks const cluster = new rds.DatabaseCluster(this, 'Database', { engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_3_02_1 }), instanceProps: { vpc, publiclyAccessible: false, }, networkType: rds.NetworkType.DUAL, }); ``` ### RDS - Working with a DB instance in a VPC https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html - CloudFormation AWS::RDS::DBInstance https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbinstance.html#cfn-rds-dbinstance-networktype ```ts declare const vpc: ec2.Vpc; // VPC and subnets must have IPv6 CIDR blocks const instance = new rds.DatabaseInstance(this, 'Instance', { engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_14_4 }), vpc, networkType: rds.NetworkType.DUAL, publiclyAccessible: false, }); ``` Note: CDK cannot check whether the specified VPC and subnets have actually IPv6 CIDR blocks because `ec2.IVpc` and `ec2.ISubnet` does not have ipv6 attributes. (cf. #19525) ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 243b4ad commit 89a7365

23 files changed

+3813
-1
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ By default, the master password will be generated and stored in AWS Secrets Mana
5050
Your cluster will be empty by default. To add a default database upon construction, specify the
5151
`defaultDatabaseName` attribute.
5252

53+
To use dual-stack mode, specify `NetworkType.DUAL` on the `networkType` property:
54+
55+
```ts
56+
declare const vpc: ec2.Vpc; // VPC and subnets must have IPv6 CIDR blocks
57+
const cluster = new rds.DatabaseCluster(this, 'Database', {
58+
engine: rds.DatabaseClusterEngine.auroraMysql({ version: rds.AuroraMysqlEngineVersion.VER_3_02_1 }),
59+
instanceProps: {
60+
vpc,
61+
publiclyAccessible: false,
62+
},
63+
networkType: rds.NetworkType.DUAL,
64+
});
65+
```
66+
67+
For more information about dual-stack mode, see [Working with a DB cluster in a VPC](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html).
68+
5369
Use `DatabaseClusterFromSnapshot` to create a cluster from a snapshot:
5470

5571
```ts
@@ -129,6 +145,20 @@ const instance = new rds.DatabaseInstance(this, 'Instance', {
129145
});
130146
```
131147

148+
To use dual-stack mode, specify `NetworkType.DUAL` on the `networkType` property:
149+
150+
```ts
151+
declare const vpc: ec2.Vpc; // VPC and subnets must have IPv6 CIDR blocks
152+
const instance = new rds.DatabaseInstance(this, 'Instance', {
153+
engine: rds.DatabaseInstanceEngine.postgres({ version: rds.PostgresEngineVersion.VER_14_4 }),
154+
vpc,
155+
networkType: rds.NetworkType.DUAL,
156+
publiclyAccessible: false,
157+
});
158+
```
159+
160+
For more information about dual-stack mode, see [Working with a DB instance in a VPC](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_VPC.WorkingWithRDSInstanceinaVPC.html).
161+
132162
Use `DatabaseInstanceFromSnapshot` and `DatabaseInstanceReadReplica` to create an instance from snapshot or
133163
a source database respectively:
134164

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { IClusterEngine } from './cluster-engine';
1111
import { DatabaseClusterAttributes, IDatabaseCluster } from './cluster-ref';
1212
import { DatabaseSecret } from './database-secret';
1313
import { Endpoint } from './endpoint';
14+
import { NetworkType } from './instance';
1415
import { IParameterGroup, ParameterGroup } from './parameter-group';
1516
import { applyDefaultRotationOptions, defaultDeletionProtection, renderCredentials, setupS3ImportExport, helperRemovalPolicy, renderUnless } from './private/util';
1617
import { BackupProps, Credentials, InstanceProps, PerformanceInsightRetention, RotationSingleUserOptions, RotationMultiUserOptions, SnapshotCredentials } from './props';
@@ -280,6 +281,13 @@ interface DatabaseClusterBaseProps {
280281
* @default - true
281282
*/
282283
readonly copyTagsToSnapshot?: boolean;
284+
285+
/**
286+
* The network type of the DB instance.
287+
*
288+
* @default - IPV4
289+
*/
290+
readonly networkType?: NetworkType;
283291
}
284292

285293
/**
@@ -481,6 +489,7 @@ abstract class DatabaseClusterNew extends DatabaseClusterBase {
481489
associatedRoles: clusterAssociatedRoles.length > 0 ? clusterAssociatedRoles : undefined,
482490
deletionProtection: defaultDeletionProtection(props.deletionProtection, props.removalPolicy),
483491
enableIamDatabaseAuthentication: props.iamAuthentication,
492+
networkType: props.networkType,
484493
// Admin
485494
backtrackWindow: props.backtrackWindow?.toSeconds(),
486495
backupRetentionPeriod: props.backup?.retention?.toDays(),

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,21 @@ export enum StorageType {
274274
IO1 = 'io1'
275275
}
276276

277+
/**
278+
* The network type of the DB instance.
279+
*/
280+
export enum NetworkType {
281+
/**
282+
* IPv4 only network type.
283+
*/
284+
IPV4 = 'IPV4',
285+
286+
/**
287+
* Dual-stack network type.
288+
*/
289+
DUAL = 'DUAL'
290+
}
291+
277292
/**
278293
* Construction properties for a DatabaseInstanceNew
279294
*/
@@ -617,6 +632,13 @@ export interface DatabaseInstanceNewProps {
617632
* @default - `true` if `vpcSubnets` is `subnetType: SubnetType.PUBLIC`, `false` otherwise
618633
*/
619634
readonly publiclyAccessible?: boolean;
635+
636+
/**
637+
* The network type of the DB instance.
638+
*
639+
* @default - IPV4
640+
*/
641+
readonly networkType?: NetworkType;
620642
}
621643

622644
/**
@@ -759,6 +781,7 @@ abstract class DatabaseInstanceNew extends DatabaseInstanceBase implements IData
759781
maxAllocatedStorage: props.maxAllocatedStorage,
760782
domain: this.domainId,
761783
domainIamRoleName: this.domainRole?.roleName,
784+
networkType: props.networkType,
762785
};
763786
}
764787

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"version": "21.0.0",
3+
"files": {
4+
"b5ff1147ce210b6a8be6120310d71e1a1bcb6c64b802b268e0b994bb80eb9ced": {
5+
"source": {
6+
"path": "aws-cdk-rds-cluster-dual-integ.template.json",
7+
"packaging": "file"
8+
},
9+
"destinations": {
10+
"current_account-current_region": {
11+
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
12+
"objectKey": "b5ff1147ce210b6a8be6120310d71e1a1bcb6c64b802b268e0b994bb80eb9ced.json",
13+
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
14+
}
15+
}
16+
}
17+
},
18+
"dockerImages": {}
19+
}

0 commit comments

Comments
 (0)