Skip to content

Commit a53517c

Browse files
feat(redshift): multi AZ cluster (#29976)
### Issue # (if applicable) Closes #<issue number here>. ### Reason for this change AWS CDK cannot configure Redshift multi-AZ cluster. ### Description of changes Add `multiAz` to `clusterProps`. ### Description of how you validated changes I've added both unit and integ tests. ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b0975e4 commit a53517c

12 files changed

+2502
-2
lines changed

packages/@aws-cdk/aws-redshift-alpha/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,28 @@ const cluster = new Cluster(this, 'Redshift', {
556556
cluster.addIamRole(role);
557557
```
558558

559+
## Multi-AZ
560+
561+
Amazon Redshift supports [multiple Availability Zones (Multi-AZ) deployments]((https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-multi-az.html)) for provisioned RA3 clusters.
562+
By using Multi-AZ deployments, your Amazon Redshift data warehouse can continue operating in failure scenarios when an unexpected event happens in an Availability Zone.
563+
564+
To create a Multi-AZ cluster, set the `multiAz` property to `true` when creating the cluster.
565+
566+
```ts
567+
declare const vpc: ec2.IVpc;
568+
569+
new redshift.Cluster(stack, 'Cluster', {
570+
masterUser: {
571+
masterUsername: 'admin',
572+
},
573+
vpc, // 3 AZs are required for Multi-AZ
574+
nodeType: redshift.NodeType.RA3_XLPLUS, // must be RA3 node type
575+
clusterType: redshift.ClusterType.MULTI_NODE, // must be MULTI_NODE
576+
numberOfNodes: 2, // must be 2 or more
577+
multiAz: true,
578+
});
579+
```
580+
559581
## Resizing
560582

561583
As your data warehousing needs change, it's possible to resize your Redshift cluster. If the cluster was deployed via CDK,

packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts

+20-1
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,13 @@ export interface ClusterProps {
385385
* @default - false
386386
*/
387387
readonly enhancedVpcRouting?: boolean;
388+
389+
/**
390+
* Indicating whether Amazon Redshift should deploy the cluster in two Availability Zones.
391+
*
392+
* @default - false
393+
*/
394+
readonly multiAz?: boolean;
388395
}
389396

390397
/**
@@ -558,6 +565,17 @@ export class Cluster extends ClusterBase {
558565
);
559566
}
560567

568+
const nodeType = props.nodeType || NodeType.DC2_LARGE;
569+
570+
if (props.multiAz) {
571+
if (!nodeType.startsWith('ra3')) {
572+
throw new Error(`Multi-AZ cluster is only supported for RA3 node types, got: ${props.nodeType}`);
573+
}
574+
if (clusterType === ClusterType.SINGLE_NODE) {
575+
throw new Error('Multi-AZ cluster is not supported for `clusterType` single-node');
576+
}
577+
}
578+
561579
this.cluster = new CfnCluster(this, 'Resource', {
562580
// Basic
563581
allowVersionUpgrade: true,
@@ -574,7 +592,7 @@ export class Cluster extends ClusterBase {
574592
?? props.masterUser.masterPassword?.unsafeUnwrap()
575593
?? 'default',
576594
preferredMaintenanceWindow: props.preferredMaintenanceWindow,
577-
nodeType: props.nodeType || NodeType.DC2_LARGE,
595+
nodeType,
578596
numberOfNodes: nodeCount,
579597
loggingProperties,
580598
iamRoles: Lazy.list({ produce: () => this.roles.map(role => role.roleArn) }, { omitEmpty: true }),
@@ -586,6 +604,7 @@ export class Cluster extends ClusterBase {
586604
classic: props.classicResizing,
587605
elasticIp: props.elasticIp,
588606
enhancedVpcRouting: props.enhancedVpcRouting,
607+
multiAz: props.multiAz,
589608
});
590609

591610
this.cluster.applyRemovalPolicy(removalPolicy, {

packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts

+62-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as iam from 'aws-cdk-lib/aws-iam';
44
import * as kms from 'aws-cdk-lib/aws-kms';
55
import * as s3 from 'aws-cdk-lib/aws-s3';
66
import * as cdk from 'aws-cdk-lib';
7-
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType } from '../lib';
7+
import { Cluster, ClusterParameterGroup, ClusterSubnetGroup, ClusterType, NodeType } from '../lib';
88
import { CfnCluster } from 'aws-cdk-lib/aws-redshift';
99

1010
let stack: cdk.Stack;
@@ -614,6 +614,67 @@ test('elastic ip address', () => {
614614
});
615615
});
616616

617+
describe('multi AZ cluster', () => {
618+
test('create a multi AZ cluster', () => {
619+
// WHEN
620+
new Cluster(stack, 'Redshift', {
621+
masterUser: {
622+
masterUsername: 'admin',
623+
masterPassword: cdk.SecretValue.unsafePlainText('tooshort'),
624+
},
625+
vpc,
626+
nodeType: NodeType.RA3_XLPLUS,
627+
multiAz: true,
628+
});
629+
630+
// THEN
631+
Template.fromStack(stack).hasResourceProperties('AWS::Redshift::Cluster', {
632+
AllowVersionUpgrade: true,
633+
MasterUsername: 'admin',
634+
MasterUserPassword: 'tooshort',
635+
ClusterType: 'multi-node',
636+
AutomatedSnapshotRetentionPeriod: 1,
637+
Encrypted: true,
638+
NumberOfNodes: 2,
639+
NodeType: 'ra3.xlplus',
640+
DBName: 'default_db',
641+
PubliclyAccessible: false,
642+
ClusterSubnetGroupName: { Ref: 'RedshiftSubnetsDFE70E0A' },
643+
VpcSecurityGroupIds: [
644+
{ 'Fn::GetAtt': ['RedshiftSecurityGroup796D74A7', 'GroupId'] },
645+
],
646+
MultiAZ: true,
647+
});
648+
});
649+
650+
test('throw error for invalid node type', () => {
651+
expect(() => {
652+
new Cluster(stack, 'Redshift', {
653+
masterUser: {
654+
masterUsername: 'admin',
655+
},
656+
vpc,
657+
nodeType: NodeType.DS2_XLARGE,
658+
multiAz: true,
659+
});
660+
}).toThrow('Multi-AZ cluster is only supported for RA3 node types, got: ds2.xlarge');
661+
});
662+
663+
test('throw error for single node cluster', () => {
664+
expect(() => {
665+
new Cluster(stack, 'Redshift', {
666+
masterUser: {
667+
masterUsername: 'admin',
668+
},
669+
vpc,
670+
nodeType: NodeType.RA3_XLPLUS,
671+
multiAz: true,
672+
clusterType: ClusterType.SINGLE_NODE,
673+
});
674+
}).toThrow('Multi-AZ cluster is not supported for `clusterType` single-node');
675+
});
676+
});
677+
617678
describe('reboot for Parameter Changes', () => {
618679
test('throw error for cluster without parameter group', () => {
619680
// Given

packages/@aws-cdk/aws-redshift-alpha/test/integ.cluster-multi-az.js.snapshot/MultiAzRedshift.assets.json

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)