Skip to content

Commit b763d86

Browse files
feat(redshift): relocating a cluster (#31993)
### Issue # (if applicable) None ### Reason for this change AWS Redshift supports for configuring [relocation a cluster](https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html) and this feature is supported by [cfn](https://docs.aws.amazon.com/ja_jp/AWSCloudFormation/latest/UserGuide/aws-resource-redshift-cluster.html#cfn-redshift-cluster-availabilityzonerelocationstatus). ### Description of changes Add `availabilityZoneRelocation` to `CusterProps`. [Documents](https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html) says that this feature is not supported for DC2 node type. ``` Relocation isn't supported on DC2 instance families of products. ``` However, this feature is only supported for RA3 node type in actual. Example implementation: ```ts new redshift.Cluster(stack, 'Cluster', { vpc: vpc, masterUser: { masterUsername: 'admin', }, availabilityZoneRelocation: true, nodeType: redshift.NodeType.DC2_LARGE, }); ``` Result: ```sh Failed resources: AzRelocationClusterStack | 6:52:00 PM | CREATE_FAILED | AWS::Redshift::Cluster | Cluster (ClusterEB0386A7) Resource handler returned message: "If the cluster node type isn?t RA3, availability zone relocation isn?t supported. (Service: Redshift, Status Code: 400, Request ID: 6382b593-cce5-4fe5-b4de-de1ad1c3a604)" (RequestToken: 94c999d9-7b72-19c4-9cfe-154fe6abc717, HandlerErrorCode: GeneralServiceException) ``` So I added this validation. ```ts if (props.availabilityZoneRelocation && !nodeType.startsWith('ra3')) { throw new Error(`Availability zone relocation is supported for only RA3 node types, got: ${props.nodeType}`); } ``` ### Description of how you validated changes Add 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 338d4c2 commit b763d86

12 files changed

+1715
-0
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,30 @@ const cluster = new Cluster(this, 'Redshift', {
7676
});
7777
```
7878

79+
## Availability Zone Relocation
80+
81+
By using [relocation in Amazon Redshift](https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html), you allow Amazon Redshift to move a cluster to another Availability Zone (AZ) without any loss of data or changes to your applications.
82+
This feature can be applied to both new and existing clusters.
83+
84+
To enable this feature, set the `availabilityZoneRelocation` property to `true`.
85+
86+
```ts
87+
import * as ec2 from 'aws-cdk-lib/aws-ec2';
88+
89+
declare const vpc: ec2.IVpc;
90+
91+
const cluster = new Cluster(this, 'Redshift', {
92+
masterUser: {
93+
masterUsername: 'admin',
94+
},
95+
vpc,
96+
nodeType: NodeType.RA3_XLPLUS,
97+
availabilityZoneRelocation: true,
98+
});
99+
```
100+
101+
**Note**: The `availabilityZoneRelocation` property is only available for RA3 node types.
102+
79103
## Connecting
80104

81105
To control who can access the cluster, use the `.connections` attribute. Redshift Clusters have

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ export interface ClusterProps {
399399
* @default - false
400400
*/
401401
readonly multiAz?: boolean;
402+
403+
/**
404+
* Whether to enable relocation for an Amazon Redshift cluster between Availability Zones after the cluster is created.
405+
*
406+
* @see https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html
407+
*
408+
* @default - false
409+
*/
410+
readonly availabilityZoneRelocation?: boolean;
402411
}
403412

404413
/**
@@ -584,6 +593,10 @@ export class Cluster extends ClusterBase {
584593
}
585594
}
586595

596+
if (props.availabilityZoneRelocation && !nodeType.startsWith('ra3')) {
597+
throw new Error(`Availability zone relocation is supported for only RA3 node types, got: ${props.nodeType}`);
598+
}
599+
587600
this.cluster = new CfnCluster(this, 'Resource', {
588601
// Basic
589602
allowVersionUpgrade: true,
@@ -613,6 +626,7 @@ export class Cluster extends ClusterBase {
613626
elasticIp: props.elasticIp,
614627
enhancedVpcRouting: props.enhancedVpcRouting,
615628
multiAz: props.multiAz,
629+
availabilityZoneRelocation: props.availabilityZoneRelocation,
616630
});
617631

618632
this.cluster.applyRemovalPolicy(removalPolicy, {

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,39 @@ test('publicly accessible cluster', () => {
432432
});
433433
});
434434

435+
test('availability zone relocation enabled', () => {
436+
// WHEN
437+
new Cluster(stack, 'Redshift', {
438+
masterUser: {
439+
masterUsername: 'admin',
440+
},
441+
vpc,
442+
availabilityZoneRelocation: true,
443+
nodeType: NodeType.RA3_XLPLUS,
444+
});
445+
446+
// THEN
447+
Template.fromStack(stack).hasResourceProperties('AWS::Redshift::Cluster', {
448+
AvailabilityZoneRelocation: true,
449+
});
450+
});
451+
452+
test.each([
453+
NodeType.DC1_8XLARGE,
454+
NodeType.DC2_LARGE,
455+
])('throw error when availability zone relocation is enabled for invalid node type %s', (nodeType) => {
456+
expect(() => {
457+
new Cluster(stack, 'Redshift', {
458+
masterUser: {
459+
masterUsername: 'admin',
460+
},
461+
vpc,
462+
availabilityZoneRelocation: true,
463+
nodeType,
464+
});
465+
}).toThrow(`Availability zone relocation is supported for only RA3 node types, got: ${nodeType}`);
466+
});
467+
435468
test('imported cluster with imported security group honors allowAllOutbound', () => {
436469
// GIVEN
437470
const cluster = Cluster.fromClusterAttributes(stack, 'Database', {

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

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)