Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(redshift): relocating a cluster #31993

Merged
merged 9 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,29 @@ const cluster = new Cluster(this, 'Redshift', {
});
```

## Availability Zone Relocation

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.

To enable this feature, set the `availabilityZoneRelocation` property to `true` when creating the cluster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify, relocation cannot be enabled after a cluster has been created?

It appears from the current README that relocation cannot be enabled after a cluster is created, but the documentation suggests that it should be possible to enable it post-creation.

https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html#cluster-recovery-console

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. I've updated description.

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.
This feature can be applied to both new and existing clusters.

To enable this feature, set the `availabilityZoneRelocation` property to `true`.


```ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';

declare const vpc: ec2.IVpc;

const cluster = new Cluster(this, 'Redshift', {
masterUser: {
masterUsername: 'admin',
},
vpc,
nodeType: NodeType.RA3_XLPLUS,
availabilityZoneRelocation: true,
});
```

**Note**: The `availabilityZoneRelocation` property is only available for RA3 node types.

## Connecting

To control who can access the cluster, use the `.connections` attribute. Redshift Clusters have
Expand Down
14 changes: 14 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ export interface ClusterProps {
* @default - false
*/
readonly multiAz?: boolean;

/**
* Whether to enable relocation for an Amazon Redshift cluster between Availability Zones after the cluster is created.
*
* @see https://docs.aws.amazon.com/redshift/latest/mgmt/managing-cluster-recovery.html
*
* @default - false
*/
readonly availabilityZoneRelocation?: boolean;
}

/**
Expand Down Expand Up @@ -584,6 +593,10 @@ export class Cluster extends ClusterBase {
}
}

if (props.availabilityZoneRelocation && !nodeType.startsWith('ra3')) {
throw new Error(`Availability zone relocation is supported for only RA3 node types, got: ${props.nodeType}`);
}

this.cluster = new CfnCluster(this, 'Resource', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.

Ensure that user activity logging is enabled for the Redshift cluster. This feature logs each query before it is executed on the cluster's database. To activate this, associate a Redshift Cluster Parameter Group with the enable_user_activity_logging parameter set to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this feedback is inappropriate. This implementation is for existing L2 code, and to avoid breaking changes, we should not forcefully enable enable_user_activity_logging.

// Basic
allowVersionUpgrade: true,
Expand Down Expand Up @@ -613,6 +626,7 @@ export class Cluster extends ClusterBase {
elasticIp: props.elasticIp,
enhancedVpcRouting: props.enhancedVpcRouting,
multiAz: props.multiAz,
availabilityZoneRelocation: props.availabilityZoneRelocation,
});

this.cluster.applyRemovalPolicy(removalPolicy, {
Expand Down
33 changes: 33 additions & 0 deletions packages/@aws-cdk/aws-redshift-alpha/test/cluster.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,39 @@ test('publicly accessible cluster', () => {
});
});

test('availability zone relocation enabled', () => {
Leo10Gama marked this conversation as resolved.
Show resolved Hide resolved
// WHEN
new Cluster(stack, 'Redshift', {
masterUser: {
masterUsername: 'admin',
},
vpc,
availabilityZoneRelocation: true,
nodeType: NodeType.RA3_XLPLUS,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::Redshift::Cluster', {
AvailabilityZoneRelocation: true,
});
});

test.each([
NodeType.DC1_8XLARGE,
NodeType.DC2_LARGE,
])('throw error when availability zone relocation is enabled for invalid node type %s', (nodeType) => {
expect(() => {
new Cluster(stack, 'Redshift', {
masterUser: {
masterUsername: 'admin',
},
vpc,
availabilityZoneRelocation: true,
nodeType,
});
}).toThrow(`Availability zone relocation is supported for only RA3 node types, got: ${nodeType}`);
});

test('imported cluster with imported security group honors allowAllOutbound', () => {
// GIVEN
const cluster = Cluster.fromClusterAttributes(stack, 'Database', {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import * as constructs from 'constructs';
import * as redshift from '../lib';

const app = new cdk.App();
const stack = new cdk.Stack(app, 'AzRelocationClusterStack');

cdk.Aspects.of(stack).add({
visit(node: constructs.IConstruct) {
if (cdk.CfnResource.isCfnResource(node)) {
node.applyRemovalPolicy(cdk.RemovalPolicy.DESTROY);
}
},
});

const vpc = new ec2.Vpc(stack, 'Vpc', {
restrictDefaultSecurityGroup: false,
natGateways: 0,
});
new redshift.Cluster(stack, 'Cluster', {
vpc: vpc,
vpcSubnets: {
subnetType: ec2.SubnetType.PUBLIC,
},
masterUser: {
masterUsername: 'admin',
},
publiclyAccessible: true,
availabilityZoneRelocation: true,
nodeType: redshift.NodeType.DC1_LARGE,
});

new integ.IntegTest(app, 'AzRelocationClusterStackInteg', {
testCases: [stack],
});

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading