Skip to content
v2.274.0

Amazon Redshift Construct Library ​

Version 2.274.0-alpha.0

Separate package

@aws-cdk/aws-redshift-alpha is not part of aws-cdk-lib — install it separately:

sh
npm install @aws-cdk/aws-redshift-alpha
pip install aws-cdk.aws-redshift-alpha

This module is experimental (alpha): its API may change in any release, without a major version bump.


cdk-constructs: Experimental

The APIs of higher level constructs in this module are experimental and under active development. They are subject to non-backward compatible changes or removal in any future version. These are not subject to the Semantic Versioning model and breaking changes will be announced in the release notes. This means that while you may use them, you may need to update your source code when upgrading to a newer version of this package.


Starting a Redshift Cluster Database ​

To set up a Redshift cluster, define a Cluster. It will be launched in a VPC. You can specify a VPC, otherwise one will be created. The nodes are always launched in private subnets and are encrypted by default.

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

const vpc = new ec2.Vpc(this, 'Vpc');
const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2


vpc = ec2.Vpc(self, "Vpc")
cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc
)
java
import software.amazon.awscdk.services.ec2.*;


Vpc vpc = new Vpc(this, "Vpc");
Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .build();
csharp
using Amazon.CDK.AWS.EC2;


var vpc = new Vpc(this, "Vpc");
var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"


vpc := ec2.NewVpc(this, jsii.String("Vpc"))
cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
})

By default, the master password will be generated and stored in AWS Secrets Manager. You can specify characters to not include in generated passwords by setting excludeCharacters property.

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

const vpc = new ec2.Vpc(this, 'Vpc');
const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
    excludeCharacters: '"@/\\\ \'`',
  },
  vpc
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2


vpc = ec2.Vpc(self, "Vpc")
cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin",
        exclude_characters="\"@/\\ '`"
    ),
    vpc=vpc
)
java
import software.amazon.awscdk.services.ec2.*;


Vpc vpc = new Vpc(this, "Vpc");
Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .excludeCharacters("\"@/\\ '`")
                .build())
        .vpc(vpc)
        .build();
csharp
using Amazon.CDK.AWS.EC2;


var vpc = new Vpc(this, "Vpc");
var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin",
        ExcludeCharacters = "\"@/\\ '`"
    },
    Vpc = vpc
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"


vpc := ec2.NewVpc(this, jsii.String("Vpc"))
cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
		ExcludeCharacters: jsii.String("\"@/\\ '`"),
	},
	Vpc: Vpc,
})

A default database named default_db will be created in the cluster. To change the name of this database set the defaultDatabaseName attribute in the constructor properties.

By default, the cluster will not be publicly accessible. Depending on your use case, you can make the cluster publicly accessible with the publiclyAccessible property.

By default, the node type is RA3_LARGE. You can specify a different node type by setting the nodeType property.

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,
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2

# vpc: ec2.IVpc


cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    node_type=NodeType.RA3_XLPLUS
)
java
import software.amazon.awscdk.services.ec2.*;

IVpc vpc;


Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .nodeType(NodeType.getRA3_XLPLUS())
        .build();
csharp
using Amazon.CDK.AWS.EC2;

IVpc vpc;


var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    NodeType = NodeType.RA3_XLPLUS
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"

var vpc IVpc


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	NodeType: nodeType_RA3_XLPLUS,
})

Database Audit Logging ​

Amazon Redshift logs information about connections and user activities in your database. These logs help you to monitor the database for security and troubleshooting purposes, a process called database auditing.

To capture user activity logs, you must also enable the enable_user_activity_logging database parameter:

ts
cluster.addToParameterGroup('enable_user_activity_logging', 'true');
python
cluster.add_to_parameter_group("enable_user_activity_logging", "true")
java
cluster.addToParameterGroup("enable_user_activity_logging", "true");
csharp
cluster.AddToParameterGroup("enable_user_activity_logging", "true");
go
cluster.AddToParameterGroup(jsii.String("enable_user_activity_logging"), jsii.String("true"))

Parameter changes on an existing cluster take effect only after a reboot. See Rebooting for Parameter Updates for how to automate it with rebootForParameterChanges.

S3 Logging ​

To send audit logs to an S3 bucket, use ClusterLogging.s3():

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as s3 from 'aws-cdk-lib/aws-s3';
import { ClusterLogging } from '@aws-cdk/aws-redshift-alpha';

declare const vpc: ec2.IVpc;
declare const bucket: s3.IBucket;

const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  logging: ClusterLogging.s3({
    bucket,
    keyPrefix: 'redshift-logs/',
  }),
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_s3 as s3
from aws_cdk.aws_redshift_alpha import ClusterLogging

# vpc: ec2.IVpc
# bucket: s3.IBucket


cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    logging=ClusterLogging.s3(
        bucket=bucket,
        key_prefix="redshift-logs/"
    )
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.s3.*;
import software.amazon.awscdk.services.redshift.alpha.ClusterLogging;

IVpc vpc;
IBucket bucket;


Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .logging(ClusterLogging.s3(S3LoggingOptions.builder()
                .bucket(bucket)
                .keyPrefix("redshift-logs/")
                .build()))
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.S3;
using Amazon.CDK.AWS.Redshift.Alpha;

IVpc vpc;
IBucket bucket;


var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    Logging = ClusterLogging.S3(new S3LoggingOptions {
        Bucket = bucket,
        KeyPrefix = "redshift-logs/"
    })
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import s3 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdkredshiftalpha"

var vpc IVpc
var bucket IBucket


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	Logging: awscdkredshiftalpha.ClusterLogging_S3(&S3LoggingOptions{
		Bucket: *Bucket,
		KeyPrefix: jsii.String("redshift-logs/"),
	}),
})

The bucket must meet the following requirements, otherwise Redshift does not deliver the logs (docs):

  • It must use Amazon S3-managed keys (SSE-S3) for encryption. SSE-KMS is not supported.
  • It must be in the same Region as the cluster.
  • S3 Object Lock must be turned off.

CloudWatch Logging ​

To send audit logs to CloudWatch, use ClusterLogging.cloudWatch(). If logExports is omitted, all log types are exported.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { ClusterLogging, LogExport } from '@aws-cdk/aws-redshift-alpha';

declare const vpc: ec2.IVpc;

const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  logging: ClusterLogging.cloudWatch({
    logExports: [LogExport.CONNECTION_LOG, LogExport.USER_LOG],
  }),
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
from aws_cdk.aws_redshift_alpha import ClusterLogging, LogExport

# vpc: ec2.IVpc


cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    logging=ClusterLogging.cloud_watch(
        log_exports=[LogExport.CONNECTION_LOG, LogExport.USER_LOG]
    )
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.redshift.alpha.ClusterLogging;
import software.amazon.awscdk.services.redshift.alpha.LogExport;

IVpc vpc;


Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .logging(ClusterLogging.cloudWatch(CloudWatchLoggingOptions.builder()
                .logExports(List.of(LogExport.CONNECTION_LOG, LogExport.USER_LOG))
                .build()))
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.Redshift.Alpha;

IVpc vpc;


var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    Logging = ClusterLogging.CloudWatch(new CloudWatchLoggingOptions {
        LogExports = new [] { LogExport.CONNECTION_LOG, LogExport.USER_LOG }
    })
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdkredshiftalpha"

var vpc IVpc


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	Logging: awscdkredshiftalpha.ClusterLogging_CloudWatch(&CloudWatchLoggingOptions{
		LogExports: []LogExport{
			awscdkredshiftalpha.LogExport_CONNECTION_LOG,
			awscdkredshiftalpha.LogExport_USER_LOG,
		},
	}),
})

Availability Zone Relocation ​

By using relocation in Amazon Redshift, 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,
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2

# vpc: ec2.IVpc


cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    node_type=NodeType.RA3_XLPLUS,
    availability_zone_relocation=True
)
java
import software.amazon.awscdk.services.ec2.*;

IVpc vpc;


Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .nodeType(NodeType.getRA3_XLPLUS())
        .availabilityZoneRelocation(true)
        .build();
csharp
using Amazon.CDK.AWS.EC2;

IVpc vpc;


var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    NodeType = NodeType.RA3_XLPLUS,
    AvailabilityZoneRelocation = true
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"

var vpc IVpc


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	NodeType: nodeType_RA3_XLPLUS,
	AvailabilityZoneRelocation: jsii.Boolean(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 a default port, so you don't need to specify the port:

ts
cluster.connections.allowDefaultPortFromAnyIpv4('Open to the world');
python
cluster.connections.allow_default_port_from_any_ipv4("Open to the world")
java
cluster.connections.allowDefaultPortFromAnyIpv4("Open to the world");
csharp
cluster.Connections.AllowDefaultPortFromAnyIpv4("Open to the world");
go
cluster.Connections.AllowDefaultPortFromAnyIpv4(jsii.String("Open to the world"))

The endpoint to access your database cluster will be available as the .clusterEndpoint attribute:

ts
cluster.clusterEndpoint.socketAddress;   // "HOSTNAME:PORT"
python
cluster.cluster_endpoint.socket_address
java
cluster.getClusterEndpoint().getSocketAddress();
csharp
cluster.ClusterEndpoint.SocketAddress;
go
cluster.ClusterEndpoint.socketAddress

Database Resources ​

This module allows for the creation of non-CloudFormation database resources such as users and tables. This allows you to manage identities, permissions, and stateful resources within your Redshift cluster from your CDK application.

Because these resources are not available in CloudFormation, this library leverages custom resources to manage them. In addition to the IAM permissions required to make Redshift service calls, the execution role for the custom resource handler requires database credentials to create resources within the cluster.

These database credentials can be supplied explicitly through the adminUser properties of the various database resource constructs. Alternatively, the credentials can be automatically pulled from the Redshift cluster's default administrator credentials. However, this option is only available if the password for the credentials was generated by the CDK application (ie., no value vas provided for the masterPassword property of Cluster.masterUser).

Creating Users ​

Create a user within a Redshift cluster database by instantiating a User construct. This will generate a username and password, store the credentials in a AWS Secrets Manager Secret, and make a query to the Redshift cluster to create a new database user with the credentials.

ts
new User(this, 'User', {
  cluster: cluster,
  databaseName: 'databaseName',
});
python
User(self, "User",
    cluster=cluster,
    database_name="databaseName"
)
java
User.Builder.create(this, "User")
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
new User(this, "User", new UserProps {
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

By default, the user credentials are encrypted with your AWS account's default Secrets Manager encryption key. You can specify the encryption key used for this purpose by supplying a key in the encryptionKey property.

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

const encryptionKey = new kms.Key(this, 'Key');
new User(this, 'User', {
  encryptionKey: encryptionKey,
  cluster: cluster,
  databaseName: 'databaseName',
});
python
import aws_cdk.aws_kms as kms


encryption_key = kms.Key(self, "Key")
User(self, "User",
    encryption_key=encryption_key,
    cluster=cluster,
    database_name="databaseName"
)
java
import software.amazon.awscdk.services.kms.*;


Key encryptionKey = new Key(this, "Key");
User.Builder.create(this, "User")
        .encryptionKey(encryptionKey)
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
using Amazon.CDK.AWS.KMS;


var encryptionKey = new Key(this, "Key");
new User(this, "User", new UserProps {
    EncryptionKey = encryptionKey,
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
import kms "github.com/aws/aws-cdk-go/awscdk"


encryptionKey := kms.NewKey(this, jsii.String("Key"))
awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	EncryptionKey: encryptionKey,
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

By default, a username is automatically generated from the user construct ID and its path in the construct tree. You can specify a particular username by providing a value for the username property. Usernames must be valid identifiers; see: Names and identifiers in the Amazon Redshift Database Developer Guide.

ts
new User(this, 'User', {
  username: 'myuser',
  cluster: cluster,
  databaseName: 'databaseName',
});
python
User(self, "User",
    username="myuser",
    cluster=cluster,
    database_name="databaseName"
)
java
User.Builder.create(this, "User")
        .username("myuser")
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
new User(this, "User", new UserProps {
    Username = "myuser",
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Username: jsii.String("myuser"),
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

The user password is generated by AWS Secrets Manager using the default configuration found in secretsmanager.SecretStringGenerator, except with password length 30 and some SQL-incompliant characters excluded. The plaintext for the password will never be present in the CDK application; instead, a CloudFormation Dynamic Reference will be used wherever the password value is required.

You can specify characters to not include in generated passwords by setting excludeCharacters property.

ts
new User(this, 'User', {
  cluster: cluster,
  databaseName: 'databaseName',
  excludeCharacters: '"@/\\\ \'`',
});
python
User(self, "User",
    cluster=cluster,
    database_name="databaseName",
    exclude_characters="\"@/\\ '`"
)
java
User.Builder.create(this, "User")
        .cluster(cluster)
        .databaseName("databaseName")
        .excludeCharacters("\"@/\\ '`")
        .build();
csharp
new User(this, "User", new UserProps {
    Cluster = cluster,
    DatabaseName = "databaseName",
    ExcludeCharacters = "\"@/\\ '`"
});
go
awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
	ExcludeCharacters: jsii.String("\"@/\\ '`"),
})

Creating Tables ​

Create a table within a Redshift cluster database by instantiating a Table construct. This will make a query to the Redshift cluster to create a new database table with the supplied schema.

ts
new Table(this, 'Table', {
  tableColumns: [{ name: 'col1', dataType: 'varchar(4)' }, { name: 'col2', dataType: 'float' }],
  cluster: cluster,
  databaseName: 'databaseName',
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)"), Column(name="col2", data_type="float")],
    cluster=cluster,
    database_name="databaseName"
)
java
Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)" }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

Tables greater than v2.114.1 can have their table name changed, for versions <= v2.114.1, this would not be possible. Therefore, changing of table names for <= v2.114.1 have been disabled.

ts
new Table(this, 'Table', {
  tableName: 'oldTableName' // This value can be change for versions greater than v2.114.1
  tableColumns: [{ name: 'col1', dataType: 'varchar(4)' }, { name: 'col2', dataType: 'float' }],
  cluster: cluster,
  databaseName: 'databaseName',
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_name="oldTableName",  # This value can be change for versions greater than v2.114.1
    table_columns=[Column(name="col1", data_type="varchar(4)"), Column(name="col2", data_type="float")],
    cluster=cluster,
    database_name="databaseName"
)
java
Table.Builder.create(this, "Table")
        .tableName("oldTableName") // This value can be change for versions greater than v2.114.1
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableName = "oldTableName",  // This value can be change for versions greater than v2.114.1
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)" }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableName: jsii.String("oldTableName"),
	 // This value can be change for versions greater than v2.114.1
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

The table can be configured to have distStyle attribute and a distKey column:

ts
new Table(this, 'Table', {
  tableColumns: [
    { name: 'col1', dataType: 'varchar(4)', distKey: true },
    { name: 'col2', dataType: 'float' },
  ],
  cluster: cluster,
  databaseName: 'databaseName',
  distStyle: TableDistStyle.KEY,
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)", dist_key=True), Column(name="col2", data_type="float")
    ],
    cluster=cluster,
    database_name="databaseName",
    dist_style=TableDistStyle.KEY
)
java
Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").distKey(true).build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .distStyle(TableDistStyle.KEY)
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)", DistKey = true }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName",
    DistStyle = TableDistStyle.KEY
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
			DistKey: jsii.Boolean(true),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
	DistStyle: awscdkredshiftalpha.TableDistStyle_KEY,
})

The table can also be configured to have sortStyle attribute and sortKey columns:

ts
new Table(this, 'Table', {
  tableColumns: [
    { name: 'col1', dataType: 'varchar(4)', sortKey: true },
    { name: 'col2', dataType: 'float', sortKey: true },
  ],
  cluster: cluster,
  databaseName: 'databaseName',
  sortStyle: TableSortStyle.COMPOUND,
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)", sort_key=True), Column(name="col2", data_type="float", sort_key=True)
    ],
    cluster=cluster,
    database_name="databaseName",
    sort_style=TableSortStyle.COMPOUND
)
java
Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").sortKey(true).build(), Column.builder().name("col2").dataType("float").sortKey(true).build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .sortStyle(TableSortStyle.COMPOUND)
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)", SortKey = true }, new Column { Name = "col2", DataType = "float", SortKey = true } },
    Cluster = cluster,
    DatabaseName = "databaseName",
    SortStyle = TableSortStyle.COMPOUND
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
			SortKey: jsii.Boolean(true),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
			SortKey: jsii.Boolean(true),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
	SortStyle: awscdkredshiftalpha.TableSortStyle_COMPOUND,
})

Tables and their respective columns can be configured to contain comments:

ts
new Table(this, 'Table', {
  tableColumns: [
    { name: 'col1', dataType: 'varchar(4)', comment: 'This is a column comment' },
    { name: 'col2', dataType: 'float', comment: 'This is a another column comment' }
  ],
  cluster: cluster,
  databaseName: 'databaseName',
  tableComment: 'This is a table comment',
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)", comment="This is a column comment"), Column(name="col2", data_type="float", comment="This is a another column comment")
    ],
    cluster=cluster,
    database_name="databaseName",
    table_comment="This is a table comment"
)
java
Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").comment("This is a column comment").build(), Column.builder().name("col2").dataType("float").comment("This is a another column comment").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .tableComment("This is a table comment")
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)", Comment = "This is a column comment" }, new Column { Name = "col2", DataType = "float", Comment = "This is a another column comment" } },
    Cluster = cluster,
    DatabaseName = "databaseName",
    TableComment = "This is a table comment"
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
			Comment: jsii.String("This is a column comment"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
			Comment: jsii.String("This is a another column comment"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
	TableComment: jsii.String("This is a table comment"),
})

Table columns can be configured to use a specific compression encoding:

ts
import { ColumnEncoding } from '@aws-cdk/aws-redshift-alpha';

new Table(this, 'Table', {
  tableColumns: [
    { name: 'col1', dataType: 'varchar(4)', encoding: ColumnEncoding.TEXT32K },
    { name: 'col2', dataType: 'float', encoding: ColumnEncoding.DELTA32K },
  ],
  cluster: cluster,
  databaseName: 'databaseName',
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
from aws_cdk.aws_redshift_alpha import ColumnEncoding


Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)", encoding=ColumnEncoding.TEXT32K), Column(name="col2", data_type="float", encoding=ColumnEncoding.DELTA32K)
    ],
    cluster=cluster,
    database_name="databaseName"
)
java
import software.amazon.awscdk.services.redshift.alpha.ColumnEncoding;


Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").encoding(ColumnEncoding.TEXT32K).build(), Column.builder().name("col2").dataType("float").encoding(ColumnEncoding.DELTA32K).build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
using Amazon.CDK.AWS.Redshift.Alpha;


new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)", Encoding = ColumnEncoding.TEXT32K }, new Column { Name = "col2", DataType = "float", Encoding = ColumnEncoding.DELTA32K } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
import "github.com/aws/aws-cdk-go/awscdkredshiftalpha"


awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
			Encoding: awscdkredshiftalpha.ColumnEncoding_TEXT32K,
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
			Encoding: awscdkredshiftalpha.ColumnEncoding_DELTA32K,
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

Table columns can also contain an id attribute, which can allow table columns to be renamed.

NOTE To use the id attribute, you must also enable the @aws-cdk/aws-redshift:columnId feature flag.

ts
new Table(this, 'Table', {
  tableColumns: [
    { id: 'col1', name: 'col1', dataType: 'varchar(4)' },
    { id: 'col2', name: 'col2', dataType: 'float' }
  ],
  cluster: cluster,
  databaseName: 'databaseName',
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
Table(self, "Table",
    table_columns=[Column(id="col1", name="col1", data_type="varchar(4)"), Column(id="col2", name="col2", data_type="float")
    ],
    cluster=cluster,
    database_name="databaseName"
)
java
Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().id("col1").name("col1").dataType("varchar(4)").build(), Column.builder().id("col2").name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
csharp
new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Id = "col1", Name = "col1", DataType = "varchar(4)" }, new Column { Id = "col2", Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});
go
awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Id: jsii.String("col1"),
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Id: jsii.String("col2"),
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

Query execution duration is limited to 1 minute by default. You can change this by setting the timeout property.

Valid timeout values are between 1 seconds and 15 minutes.

ts
import { Duration } from 'aws-cdk-lib';

new Table(this, 'Table', {
  tableColumns: [
    { id: 'col1', name: 'col1', dataType: 'varchar(4)' },
    { id: 'col2', name: 'col2', dataType: 'float' }
  ],
  cluster: cluster,
  databaseName: 'databaseName',
  timeout: Duration.minutes(15),
});
python
from aws_cdk.aws_redshift_alpha import Column, Column
from aws_cdk import Duration


Table(self, "Table",
    table_columns=[Column(id="col1", name="col1", data_type="varchar(4)"), Column(id="col2", name="col2", data_type="float")
    ],
    cluster=cluster,
    database_name="databaseName",
    timeout=Duration.minutes(15)
)
java
import software.amazon.awscdk.Duration;


Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().id("col1").name("col1").dataType("varchar(4)").build(), Column.builder().id("col2").name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .timeout(Duration.minutes(15))
        .build();
csharp
using Amazon.CDK;

new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Id = "col1", Name = "col1", DataType = "varchar(4)" }, new Column { Id = "col2", Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName",
    Timeout = Duration.Minutes(15)
});
go
import "github.com/aws/aws-cdk-go/awscdk"


awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Id: jsii.String("col1"),
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Id: jsii.String("col2"),
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
	Timeout: awscdk.Duration_Minutes(jsii.Number(15)),
})

Granting Privileges ​

You can give a user privileges to perform certain actions on a table by using the Table.grant() method.

ts
const user = new User(this, 'User', {
  cluster: cluster,
  databaseName: 'databaseName',
});
const table = new Table(this, 'Table', {
  tableColumns: [{ name: 'col1', dataType: 'varchar(4)' }, { name: 'col2', dataType: 'float' }],
  cluster: cluster,
  databaseName: 'databaseName',
});

table.grant(user, TableAction.DROP, TableAction.SELECT);
python
from aws_cdk.aws_redshift_alpha import Column, Column
user = User(self, "User",
    cluster=cluster,
    database_name="databaseName"
)
table = Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)"), Column(name="col2", data_type="float")],
    cluster=cluster,
    database_name="databaseName"
)

table.grant(user, TableAction.DROP, TableAction.SELECT)
java
User user = User.Builder.create(this, "User")
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
Table table = Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build();

table.grant(user, TableAction.DROP, TableAction.SELECT);
csharp
var user = new User(this, "User", new UserProps {
    Cluster = cluster,
    DatabaseName = "databaseName"
});
var table = new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)" }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});

table.Grant(user, TableAction.DROP, TableAction.SELECT);
go
user := awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})
table := awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})

table.grant(user, awscdkredshiftalpha.TableAction_DROP, awscdkredshiftalpha.TableAction_SELECT)

Take care when managing privileges via the CDK, as attempting to manage a user's privileges on the same table in multiple CDK applications could lead to accidentally overriding these permissions. Consider the following two CDK applications which both refer to the same user and table. In application 1, the resources are created and the user is given INSERT permissions on the table:

ts
const databaseName = 'databaseName';
const username = 'myuser'
const tableName = 'mytable'

const user = new User(this, 'User', {
  username: username,
  cluster: cluster,
  databaseName: databaseName,
});
const table = new Table(this, 'Table', {
  tableColumns: [{ name: 'col1', dataType: 'varchar(4)' }, { name: 'col2', dataType: 'float' }],
  cluster: cluster,
  databaseName: databaseName,
});
table.grant(user, TableAction.INSERT);
python
from aws_cdk.aws_redshift_alpha import Column, Column
database_name = "databaseName"
username = "myuser"
table_name = "mytable"

user = User(self, "User",
    username=username,
    cluster=cluster,
    database_name=database_name
)
table = Table(self, "Table",
    table_columns=[Column(name="col1", data_type="varchar(4)"), Column(name="col2", data_type="float")],
    cluster=cluster,
    database_name=database_name
)
table.grant(user, TableAction.INSERT)
java
String databaseName = "databaseName";
String username = "myuser";
String tableName = "mytable";

User user = User.Builder.create(this, "User")
        .username(username)
        .cluster(cluster)
        .databaseName(databaseName)
        .build();
Table table = Table.Builder.create(this, "Table")
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName(databaseName)
        .build();
table.grant(user, TableAction.INSERT);
csharp
var databaseName = "databaseName";
var username = "myuser";
var tableName = "mytable";

var user = new User(this, "User", new UserProps {
    Username = username,
    Cluster = cluster,
    DatabaseName = databaseName
});
var table = new Table(this, "Table", new TableProps {
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)" }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = databaseName
});
table.Grant(user, TableAction.INSERT);
go
databaseName := "databaseName"
username := "myuser"
tableName := "mytable"

user := awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Username: username,
	Cluster: cluster,
	DatabaseName: databaseName,
})
table := awscdkredshiftalpha.NewTable(this, jsii.String("Table"), &TableProps{
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: databaseName,
})
table.grant(user, awscdkredshiftalpha.TableAction_INSERT)

In application 2, the resources are imported and the user is given INSERT permissions on the table:

ts
const databaseName = 'databaseName';
const username = 'myuser'
const tableName = 'mytable'

const user = User.fromUserAttributes(this, 'User', {
  username: username,
  password: SecretValue.unsafePlainText('NOT_FOR_PRODUCTION'),
  cluster: cluster,
  databaseName: databaseName,
});
const table = Table.fromTableAttributes(this, 'Table', {
  tableName: tableName,
  tableColumns: [{ name: 'col1', dataType: 'varchar(4)' }, { name: 'col2', dataType: 'float' }],
  cluster: cluster,
  databaseName: 'databaseName',
});
table.grant(user, TableAction.INSERT);
python
from aws_cdk.aws_redshift_alpha import Column, Column
database_name = "databaseName"
username = "myuser"
table_name = "mytable"

user = User.from_user_attributes(self, "User",
    username=username,
    password=SecretValue.unsafe_plain_text("NOT_FOR_PRODUCTION"),
    cluster=cluster,
    database_name=database_name
)
table = Table.from_table_attributes(self, "Table",
    table_name=table_name,
    table_columns=[Column(name="col1", data_type="varchar(4)"), Column(name="col2", data_type="float")],
    cluster=cluster,
    database_name="databaseName"
)
table.grant(user, TableAction.INSERT)
java
String databaseName = "databaseName";
String username = "myuser";
String tableName = "mytable";

IUser user = User.fromUserAttributes(this, "User", UserAttributes.builder()
        .username(username)
        .password(SecretValue.unsafePlainText("NOT_FOR_PRODUCTION"))
        .cluster(cluster)
        .databaseName(databaseName)
        .build());
ITable table = Table.fromTableAttributes(this, "Table", TableAttributes.builder()
        .tableName(tableName)
        .tableColumns(List.of(Column.builder().name("col1").dataType("varchar(4)").build(), Column.builder().name("col2").dataType("float").build()))
        .cluster(cluster)
        .databaseName("databaseName")
        .build());
table.grant(user, TableAction.INSERT);
csharp
var databaseName = "databaseName";
var username = "myuser";
var tableName = "mytable";

var user = User.FromUserAttributes(this, "User", new UserAttributes {
    Username = username,
    Password = SecretValue.UnsafePlainText("NOT_FOR_PRODUCTION"),
    Cluster = cluster,
    DatabaseName = databaseName
});
var table = Table.FromTableAttributes(this, "Table", new TableAttributes {
    TableName = tableName,
    TableColumns = new [] { new Column { Name = "col1", DataType = "varchar(4)" }, new Column { Name = "col2", DataType = "float" } },
    Cluster = cluster,
    DatabaseName = "databaseName"
});
table.Grant(user, TableAction.INSERT);
go
databaseName := "databaseName"
username := "myuser"
tableName := "mytable"

user := awscdkredshiftalpha.User_FromUserAttributes(this, jsii.String("User"), &UserAttributes{
	Username: username,
	Password: awscdk.SecretValue_UnsafePlainText(jsii.String("NOT_FOR_PRODUCTION")),
	Cluster: cluster,
	DatabaseName: databaseName,
})
table := awscdkredshiftalpha.Table_FromTableAttributes(this, jsii.String("Table"), &TableAttributes{
	TableName: tableName,
	TableColumns: []Column{
		&Column{
			Name: jsii.String("col1"),
			DataType: jsii.String("varchar(4)"),
		},
		&Column{
			Name: jsii.String("col2"),
			DataType: jsii.String("float"),
		},
	},
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})
table.Grant(user, awscdkredshiftalpha.TableAction_INSERT)

Both applications attempt to grant the user the appropriate privilege on the table by submitting a GRANT USER SQL query to the Redshift cluster. Note that the latter of these two calls will have no effect since the user has already been granted the privilege.

Now, if application 1 were to remove the call to grant, a REVOKE USER SQL query is submitted to the Redshift cluster. In general, application 1 does not know that application 2 has also granted this permission and thus cannot decide not to issue the revocation. This leads to the undesirable state where application 2 still contains the call to grant but the user does not have the specified permission.

Note that this does not occur when duplicate privileges are granted within the same application, as such privileges are de-duplicated before any SQL query is submitted.

Rotating credentials ​

When the master password is generated and stored in AWS Secrets Manager, it can be rotated automatically:

ts
cluster.addRotationSingleUser(); // Will rotate automatically after 30 days
python
cluster.add_rotation_single_user()
java
cluster.addRotationSingleUser();
csharp
cluster.AddRotationSingleUser();
go
cluster.AddRotationSingleUser()

The multi user rotation scheme is also available:

ts

const user = new User(this, 'User', {
  cluster: cluster,
  databaseName: 'databaseName',
});
cluster.addRotationMultiUser('MultiUserRotation', {
  secret: user.secret,
});
python
user = User(self, "User",
    cluster=cluster,
    database_name="databaseName"
)
cluster.add_rotation_multi_user("MultiUserRotation",
    secret=user.secret
)
java
User user = User.Builder.create(this, "User")
        .cluster(cluster)
        .databaseName("databaseName")
        .build();
cluster.addRotationMultiUser("MultiUserRotation", RotationMultiUserOptions.builder()
        .secret(user.getSecret())
        .build());
csharp
var user = new User(this, "User", new UserProps {
    Cluster = cluster,
    DatabaseName = "databaseName"
});
cluster.AddRotationMultiUser("MultiUserRotation", new RotationMultiUserOptions {
    Secret = user.Secret
});
go
user := awscdkredshiftalpha.NewUser(this, jsii.String("User"), &UserProps{
	Cluster: cluster,
	DatabaseName: jsii.String("databaseName"),
})
cluster.AddRotationMultiUser(jsii.String("MultiUserRotation"), &RotationMultiUserOptions{
	Secret: user.Secret,
})

Adding Parameters ​

You can add a parameter to a parameter group withClusterParameterGroup.addParameter().

ts
import { ClusterParameterGroup } from '@aws-cdk/aws-redshift-alpha';

const params = new ClusterParameterGroup(this, 'Params', {
  description: 'desc',
  parameters: {
    require_ssl: 'true',
  },
});

params.addParameter('enable_user_activity_logging', 'true');
python
from aws_cdk.aws_redshift_alpha import ClusterParameterGroup


params = ClusterParameterGroup(self, "Params",
    description="desc",
    parameters={
        "require_ssl": "true"
    }
)

params.add_parameter("enable_user_activity_logging", "true")
java
import software.amazon.awscdk.services.redshift.alpha.ClusterParameterGroup;


ClusterParameterGroup params = ClusterParameterGroup.Builder.create(this, "Params")
        .description("desc")
        .parameters(Map.of(
                "require_ssl", "true"))
        .build();

params.addParameter("enable_user_activity_logging", "true");
csharp
using Amazon.CDK.AWS.Redshift.Alpha;


var params = new ClusterParameterGroup(this, "Params", new ClusterParameterGroupProps {
    Description = "desc",
    Parameters = new Dictionary<string, string> {
        { "require_ssl", "true" }
    }
});

params.AddParameter("enable_user_activity_logging", "true");
go
import "github.com/aws/aws-cdk-go/awscdkredshiftalpha"


params := awscdkredshiftalpha.NewClusterParameterGroup(this, jsii.String("Params"), &ClusterParameterGroupProps{
	Description: jsii.String("desc"),
	Parameters: map[string]*string{
		"require_ssl": jsii.String("true"),
	},
})

params.AddParameter(jsii.String("enable_user_activity_logging"), jsii.String("true"))

Additionally, you can add a parameter to the cluster's associated parameter group with Cluster.addToParameterGroup(). If the cluster does not have an associated parameter group, a new parameter group is created.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
declare const vpc: ec2.Vpc;

const cluster = new Cluster(this, 'Cluster', {
  masterUser: {
    masterUsername: 'admin',
    masterPassword: cdk.SecretValue.unsafePlainText('tooshort'),
  },
  vpc,
});

cluster.addToParameterGroup('enable_user_activity_logging', 'true');
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk as cdk
# vpc: ec2.Vpc


cluster = Cluster(self, "Cluster",
    master_user=Login(
        master_username="admin",
        master_password=cdk.SecretValue.unsafe_plain_text("tooshort")
    ),
    vpc=vpc
)

cluster.add_to_parameter_group("enable_user_activity_logging", "true")
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.*;
Vpc vpc;


Cluster cluster = Cluster.Builder.create(this, "Cluster")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .masterPassword(SecretValue.unsafePlainText("tooshort"))
                .build())
        .vpc(vpc)
        .build();

cluster.addToParameterGroup("enable_user_activity_logging", "true");
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK;
Vpc vpc;

var cluster = new Cluster(this, "Cluster", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin",
        MasterPassword = SecretValue.UnsafePlainText("tooshort")
    },
    Vpc = vpc
});

cluster.AddToParameterGroup("enable_user_activity_logging", "true");
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import cdk "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Cluster"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
		MasterPassword: cdk.SecretValue_UnsafePlainText(jsii.String("tooshort")),
	},
	Vpc: Vpc,
})

cluster.AddToParameterGroup(jsii.String("enable_user_activity_logging"), jsii.String("true"))

Rebooting for Parameter Updates ​

In most cases, existing clusters must be manually rebooted to apply parameter changes. You can automate parameter related reboots by setting the cluster's rebootForParameterChanges property to true , or by using Cluster.enableRebootForParameterChanges().

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
declare const vpc: ec2.Vpc;

const cluster = new Cluster(this, 'Cluster', {
  masterUser: {
    masterUsername: 'admin',
    masterPassword: cdk.SecretValue.unsafePlainText('tooshort'),
  },
  vpc,
});

cluster.addToParameterGroup('enable_user_activity_logging', 'true');
cluster.enableRebootForParameterChanges()
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk as cdk
# vpc: ec2.Vpc


cluster = Cluster(self, "Cluster",
    master_user=Login(
        master_username="admin",
        master_password=cdk.SecretValue.unsafe_plain_text("tooshort")
    ),
    vpc=vpc
)

cluster.add_to_parameter_group("enable_user_activity_logging", "true")
cluster.enable_reboot_for_parameter_changes()
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.*;
Vpc vpc;


Cluster cluster = Cluster.Builder.create(this, "Cluster")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .masterPassword(SecretValue.unsafePlainText("tooshort"))
                .build())
        .vpc(vpc)
        .build();

cluster.addToParameterGroup("enable_user_activity_logging", "true");
cluster.enableRebootForParameterChanges();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK;
Vpc vpc;

var cluster = new Cluster(this, "Cluster", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin",
        MasterPassword = SecretValue.UnsafePlainText("tooshort")
    },
    Vpc = vpc
});

cluster.AddToParameterGroup("enable_user_activity_logging", "true");
cluster.EnableRebootForParameterChanges();
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import cdk "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Cluster"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
		MasterPassword: cdk.SecretValue_UnsafePlainText(jsii.String("tooshort")),
	},
	Vpc: Vpc,
})

cluster.AddToParameterGroup(jsii.String("enable_user_activity_logging"), jsii.String("true"))
cluster.EnableRebootForParameterChanges()

Resource Action ​

You can perform various actions on the Redshift resource by specifying the resourceAction property, including pausing and resuming the cluster, as well as initiating failover for Multi-AZ clusters.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import { ResourceAction } from '@aws-cdk/aws-redshift-alpha';

declare const vpc: ec2.IVpc;

// Pause the cluster
new Cluster(this, 'PausedCluster', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  resourceAction: ResourceAction.PAUSE,
});

// Resume the cluster
new Cluster(this, 'ResumedCluster', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  resourceAction: ResourceAction.RESUME,
});

// Failover the cluster
new Cluster(this, 'FailOverCluster', {
  masterUser: {
    masterUsername: 'admin',
  },
  // VPC must have 3 AZs for the cluster which executes failover action
  vpc,
  // Must be a multi-AZ cluster to failover
  multiAz: true,
  resourceAction: ResourceAction.FAILOVER_PRIMARY_COMPUTE,
});
python
from aws_cdk.aws_redshift_alpha import Login, Login, Login
import aws_cdk.aws_ec2 as ec2
from aws_cdk.aws_redshift_alpha import ResourceAction

# vpc: ec2.IVpc


# Pause the cluster
Cluster(self, "PausedCluster",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    resource_action=ResourceAction.PAUSE
)

# Resume the cluster
Cluster(self, "ResumedCluster",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    resource_action=ResourceAction.RESUME
)

# Failover the cluster
Cluster(self, "FailOverCluster",
    master_user=Login(
        master_username="admin"
    ),
    # VPC must have 3 AZs for the cluster which executes failover action
    vpc=vpc,
    # Must be a multi-AZ cluster to failover
    multi_az=True,
    resource_action=ResourceAction.FAILOVER_PRIMARY_COMPUTE
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.redshift.alpha.ResourceAction;

IVpc vpc;


// Pause the cluster
// Pause the cluster
Cluster.Builder.create(this, "PausedCluster")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .resourceAction(ResourceAction.PAUSE)
        .build();

// Resume the cluster
// Resume the cluster
Cluster.Builder.create(this, "ResumedCluster")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .resourceAction(ResourceAction.RESUME)
        .build();

// Failover the cluster
// Failover the cluster
Cluster.Builder.create(this, "FailOverCluster")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        // VPC must have 3 AZs for the cluster which executes failover action
        .vpc(vpc)
        // Must be a multi-AZ cluster to failover
        .multiAz(true)
        .resourceAction(ResourceAction.FAILOVER_PRIMARY_COMPUTE)
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.Redshift.Alpha;

IVpc vpc;


// Pause the cluster
// Pause the cluster
new Cluster(this, "PausedCluster", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    ResourceAction = ResourceAction.PAUSE
});

// Resume the cluster
// Resume the cluster
new Cluster(this, "ResumedCluster", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    ResourceAction = ResourceAction.RESUME
});

// Failover the cluster
// Failover the cluster
new Cluster(this, "FailOverCluster", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    // VPC must have 3 AZs for the cluster which executes failover action
    Vpc = vpc,
    // Must be a multi-AZ cluster to failover
    MultiAz = true,
    ResourceAction = ResourceAction.FAILOVER_PRIMARY_COMPUTE
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdkredshiftalpha"

var vpc IVpc


// Pause the cluster
// Pause the cluster
awscdkredshiftalpha.NewCluster(this, jsii.String("PausedCluster"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	ResourceAction: awscdkredshiftalpha.ResourceAction_PAUSE,
})

// Resume the cluster
// Resume the cluster
awscdkredshiftalpha.NewCluster(this, jsii.String("ResumedCluster"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	ResourceAction: awscdkredshiftalpha.ResourceAction_RESUME,
})

// Failover the cluster
// Failover the cluster
awscdkredshiftalpha.NewCluster(this, jsii.String("FailOverCluster"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	// VPC must have 3 AZs for the cluster which executes failover action
	Vpc: Vpc,
	// Must be a multi-AZ cluster to failover
	MultiAz: jsii.Boolean(true),
	ResourceAction: awscdkredshiftalpha.ResourceAction_FAILOVER_PRIMARY_COMPUTE,
})

Elastic IP ​

If you configure your cluster to be publicly accessible, you can optionally select an elastic IP address to use for the external IP address. An elastic IP address is a static IP address that is associated with your AWS account. You can use an elastic IP address to connect to your cluster from outside the VPC. An elastic IP address gives you the ability to change your underlying configuration without affecting the IP address that clients use to connect to your cluster. This approach can be helpful for situations such as recovery after a failure.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
declare const vpc: ec2.Vpc;

new Cluster(this, 'Redshift', {
    masterUser: {
      masterUsername: 'admin',
      masterPassword: cdk.SecretValue.unsafePlainText('tooshort'),
    },
    vpc,
    publiclyAccessible: true,
    elasticIp: '10.123.123.255', // A elastic ip you own
})
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk as cdk
# vpc: ec2.Vpc


Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin",
        master_password=cdk.SecretValue.unsafe_plain_text("tooshort")
    ),
    vpc=vpc,
    publicly_accessible=True,
    elastic_ip="10.123.123.255"
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.*;
Vpc vpc;


Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .masterPassword(SecretValue.unsafePlainText("tooshort"))
                .build())
        .vpc(vpc)
        .publiclyAccessible(true)
        .elasticIp("10.123.123.255")
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK;
Vpc vpc;

new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin",
        MasterPassword = SecretValue.UnsafePlainText("tooshort")
    },
    Vpc = vpc,
    PubliclyAccessible = true,
    ElasticIp = "10.123.123.255"
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import cdk "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
		MasterPassword: cdk.SecretValue_UnsafePlainText(jsii.String("tooshort")),
	},
	Vpc: Vpc,
	PubliclyAccessible: jsii.Boolean(true),
	ElasticIp: jsii.String("10.123.123.255"),
})

If the Cluster is in a VPC and you want to connect to it using the private IP address from within the cluster, it is important to enable DNS resolution and DNS hostnames in the VPC config. If these parameters would not be set, connections from within the VPC would connect to the elastic IP address and not the private IP address.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
const vpc = new ec2.Vpc(this, 'VPC', {
  enableDnsSupport: true,
  enableDnsHostnames: true,
});
python
import aws_cdk.aws_ec2 as ec2

vpc = ec2.Vpc(self, "VPC",
    enable_dns_support=True,
    enable_dns_hostnames=True
)
java
import software.amazon.awscdk.services.ec2.*;

Vpc vpc = Vpc.Builder.create(this, "VPC")
        .enableDnsSupport(true)
        .enableDnsHostnames(true)
        .build();
csharp
using Amazon.CDK.AWS.EC2;

var vpc = new Vpc(this, "VPC", new VpcProps {
    EnableDnsSupport = true,
    EnableDnsHostnames = true
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"

vpc := ec2.NewVpc(this, jsii.String("VPC"), &VpcProps{
	EnableDnsSupport: jsii.Boolean(true),
	EnableDnsHostnames: jsii.Boolean(true),
})

Note that if there is already an existing, public accessible Cluster, which VPC configuration is changed to use DNS hostnames and DNS resolution, connections still use the elastic IP address until the cluster is resized.

Elastic IP vs. Cluster node public IP ​

The elastic IP address is an external IP address for accessing the cluster outside of a VPC. It's not related to the cluster node public IP addresses and private IP addresses that are accessible via the clusterEndpoint property. The public and private cluster node IP addresses appear regardless of whether the cluster is publicly accessible or not. They are used only in certain circumstances to configure ingress rules on the remote host. These circumstances occur when you load data from an Amazon EC2 instance or other remote host using a Secure Shell (SSH) connection.

Attach Elastic IP after Cluster creation ​

In some cases, you might want to associate the cluster with an elastic IP address or change an elastic IP address that is associated with the cluster. To attach an elastic IP address after the cluster is created, first update the cluster so that it is not publicly accessible, then make it both publicly accessible and add an Elastic IP address in the same operation.

Enhanced VPC Routing ​

When you use Amazon Redshift enhanced VPC routing, Amazon Redshift forces all COPY and UNLOAD traffic between your cluster and your data repositories through your virtual private cloud (VPC) based on the Amazon VPC service. By using enhanced VPC routing, you can use standard VPC features, such as VPC security groups, network access control lists (ACLs), VPC endpoints, VPC endpoint policies, internet gateways, and Domain Name System (DNS) servers, as described in the Amazon VPC User Guide. You use these features to tightly manage the flow of data between your Amazon Redshift cluster and other resources. When you use enhanced VPC routing to route traffic through your VPC, you can also use VPC flow logs to monitor COPY and UNLOAD traffic.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
declare const vpc: ec2.Vpc;

new Cluster(this, 'Redshift', {
    masterUser: {
      masterUsername: 'admin',
      masterPassword: cdk.SecretValue.unsafePlainText('tooshort'),
    },
    vpc,
    enhancedVpcRouting: true,
})
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk as cdk
# vpc: ec2.Vpc


Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin",
        master_password=cdk.SecretValue.unsafe_plain_text("tooshort")
    ),
    vpc=vpc,
    enhanced_vpc_routing=True
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.*;
Vpc vpc;


Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .masterPassword(SecretValue.unsafePlainText("tooshort"))
                .build())
        .vpc(vpc)
        .enhancedVpcRouting(true)
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK;
Vpc vpc;

new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin",
        MasterPassword = SecretValue.UnsafePlainText("tooshort")
    },
    Vpc = vpc,
    EnhancedVpcRouting = true
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import cdk "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
		MasterPassword: cdk.SecretValue_UnsafePlainText(jsii.String("tooshort")),
	},
	Vpc: Vpc,
	EnhancedVpcRouting: jsii.Boolean(true),
})

If enhanced VPC routing is not enabled, Amazon Redshift routes traffic through the internet, including traffic to other services within the AWS network.

Default IAM role ​

Some Amazon Redshift features require Amazon Redshift to access other AWS services on your behalf. For your Amazon Redshift clusters to act on your behalf, you supply security credentials to your clusters. The preferred method to supply security credentials is to specify an AWS Identity and Access Management (IAM) role.

When you create an IAM role and set it as the default for the cluster using console, you don't have to provide the IAM role's Amazon Resource Name (ARN) to perform authentication and authorization.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const vpc: ec2.Vpc;

const defaultRole = new iam.Role(this, 'DefaultRole', {
  assumedBy: new iam.ServicePrincipal('redshift.amazonaws.com'),
},
);

new Cluster(this, 'Redshift', {
    masterUser: {
      masterUsername: 'admin',
    },
    vpc,
    roles: [defaultRole],
    defaultRole: defaultRole,
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_iam as iam
# vpc: ec2.Vpc


default_role = iam.Role(self, "DefaultRole",
    assumed_by=iam.ServicePrincipal("redshift.amazonaws.com")
)

Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    roles=[default_role],
    default_role=default_role
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
Vpc vpc;


Role defaultRole = Role.Builder.create(this, "DefaultRole")
        .assumedBy(new ServicePrincipal("redshift.amazonaws.com"))
        .build();

Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .roles(List.of(defaultRole))
        .defaultRole(defaultRole)
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
Vpc vpc;


var defaultRole = new Role(this, "DefaultRole", new RoleProps {
    AssumedBy = new ServicePrincipal("redshift.amazonaws.com")
});

new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    Roles = new [] { defaultRole },
    DefaultRole = defaultRole
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


defaultRole := iam.NewRole(this, jsii.String("DefaultRole"), &RoleProps{
	AssumedBy: iam.NewServicePrincipal(jsii.String("redshift.amazonaws.com")),
})

awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	Roles: []IRole{
		defaultRole,
	},
	DefaultRole: defaultRole,
})

A default role can also be added to a cluster using the addDefaultIamRole method.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const vpc: ec2.Vpc;

const defaultRole = new iam.Role(this, 'DefaultRole', {
  assumedBy: new iam.ServicePrincipal('redshift.amazonaws.com'),
},
);

const redshiftCluster = new Cluster(this, 'Redshift', {
    masterUser: {
      masterUsername: 'admin',
    },
    vpc,
    roles: [defaultRole],
});

redshiftCluster.addDefaultIamRole(defaultRole);
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_iam as iam
# vpc: ec2.Vpc


default_role = iam.Role(self, "DefaultRole",
    assumed_by=iam.ServicePrincipal("redshift.amazonaws.com")
)

redshift_cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    roles=[default_role]
)

redshift_cluster.add_default_iam_role(default_role)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
Vpc vpc;


Role defaultRole = Role.Builder.create(this, "DefaultRole")
        .assumedBy(new ServicePrincipal("redshift.amazonaws.com"))
        .build();

Cluster redshiftCluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .roles(List.of(defaultRole))
        .build();

redshiftCluster.addDefaultIamRole(defaultRole);
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
Vpc vpc;


var defaultRole = new Role(this, "DefaultRole", new RoleProps {
    AssumedBy = new ServicePrincipal("redshift.amazonaws.com")
});

var redshiftCluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    Roles = new [] { defaultRole }
});

redshiftCluster.AddDefaultIamRole(defaultRole);
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


defaultRole := iam.NewRole(this, jsii.String("DefaultRole"), &RoleProps{
	AssumedBy: iam.NewServicePrincipal(jsii.String("redshift.amazonaws.com")),
})

redshiftCluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	Roles: []IRole{
		defaultRole,
	},
})

redshiftCluster.AddDefaultIamRole(defaultRole)

IAM roles ​

Attaching IAM roles to a Redshift Cluster grants permissions to the Redshift service to perform actions on your behalf.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const vpc: ec2.Vpc

const role = new iam.Role(this, 'Role', {
  assumedBy: new iam.ServicePrincipal('redshift.amazonaws.com'),
});
const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  roles: [role],
});
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_iam as iam
# vpc: ec2.Vpc


role = iam.Role(self, "Role",
    assumed_by=iam.ServicePrincipal("redshift.amazonaws.com")
)
cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc,
    roles=[role]
)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
Vpc vpc;


Role role = Role.Builder.create(this, "Role")
        .assumedBy(new ServicePrincipal("redshift.amazonaws.com"))
        .build();
Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .roles(List.of(role))
        .build();
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
Vpc vpc;


var role = new Role(this, "Role", new RoleProps {
    AssumedBy = new ServicePrincipal("redshift.amazonaws.com")
});
var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    Roles = new [] { role }
});
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


role := iam.NewRole(this, jsii.String("Role"), &RoleProps{
	AssumedBy: iam.NewServicePrincipal(jsii.String("redshift.amazonaws.com")),
})
cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
	Roles: []IRole{
		role,
	},
})

Additional IAM roles can be attached to a cluster using the addIamRole method.

ts
import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as iam from 'aws-cdk-lib/aws-iam';
declare const vpc: ec2.Vpc

const role = new iam.Role(this, 'Role', {
  assumedBy: new iam.ServicePrincipal('redshift.amazonaws.com'),
});
const cluster = new Cluster(this, 'Redshift', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
});
cluster.addIamRole(role);
python
from aws_cdk.aws_redshift_alpha import Login
import aws_cdk.aws_ec2 as ec2
import aws_cdk.aws_iam as iam
# vpc: ec2.Vpc


role = iam.Role(self, "Role",
    assumed_by=iam.ServicePrincipal("redshift.amazonaws.com")
)
cluster = Cluster(self, "Redshift",
    master_user=Login(
        master_username="admin"
    ),
    vpc=vpc
)
cluster.add_iam_role(role)
java
import software.amazon.awscdk.services.ec2.*;
import software.amazon.awscdk.services.iam.*;
Vpc vpc;


Role role = Role.Builder.create(this, "Role")
        .assumedBy(new ServicePrincipal("redshift.amazonaws.com"))
        .build();
Cluster cluster = Cluster.Builder.create(this, "Redshift")
        .masterUser(Login.builder()
                .masterUsername("admin")
                .build())
        .vpc(vpc)
        .build();
cluster.addIamRole(role);
csharp
using Amazon.CDK.AWS.EC2;
using Amazon.CDK.AWS.IAM;
Vpc vpc;


var role = new Role(this, "Role", new RoleProps {
    AssumedBy = new ServicePrincipal("redshift.amazonaws.com")
});
var cluster = new Cluster(this, "Redshift", new ClusterProps {
    MasterUser = new Login {
        MasterUsername = "admin"
    },
    Vpc = vpc
});
cluster.AddIamRole(role);
go
import ec2 "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"
var vpc Vpc


role := iam.NewRole(this, jsii.String("Role"), &RoleProps{
	AssumedBy: iam.NewServicePrincipal(jsii.String("redshift.amazonaws.com")),
})
cluster := awscdkredshiftalpha.NewCluster(this, jsii.String("Redshift"), &ClusterProps{
	MasterUser: &Login{
		MasterUsername: jsii.String("admin"),
	},
	Vpc: Vpc,
})
cluster.AddIamRole(role)

Multi-AZ ​

Amazon Redshift supports multiple Availability Zones (Multi-AZ) deployments) for provisioned RA3 clusters. 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.

To create a Multi-AZ cluster, set the multiAz property to true when creating the cluster.

ts
declare const vpc: ec2.IVpc;

new redshift.Cluster(stack, 'Cluster', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc, // 3 AZs are required for Multi-AZ
  nodeType: redshift.NodeType.RA3_XLPLUS, // must be RA3 node type
  clusterType: redshift.ClusterType.MULTI_NODE, // must be MULTI_NODE
  numberOfNodes: 2, // must be 2 or more
  multiAz: true,
});
python
# vpc: ec2.IVpc


redshift.Cluster(stack, "Cluster",
    master_user={
        "master_username": "admin"
    },
    vpc=vpc,  # 3 AZs are required for Multi-AZ
    node_type=redshift.NodeType.RA3_XLPLUS,  # must be RA3 node type
    cluster_type=redshift.ClusterType.MULTI_NODE,  # must be MULTI_NODE
    number_of_nodes=2,  # must be 2 or more
    multi_az=True
)
java
ec2.IVpc vpc;


Cluster.Builder.create(stack, "Cluster")
        .masterUser(Map.of(
                "masterUsername", "admin"))
        .vpc(vpc) // 3 AZs are required for Multi-AZ
        .nodeType(redshift.getNodeType().getRA3_XLPLUS()) // must be RA3 node type
        .clusterType(redshift.getClusterType().getMULTI_NODE()) // must be MULTI_NODE
        .numberOfNodes(2) // must be 2 or more
        .multiAz(true)
        .build();
csharp
ec2.IVpc vpc;


new redshift.Cluster(stack, "Cluster", new Struct {
    MasterUser = new Struct {
        MasterUsername = "admin"
    },
    Vpc = vpc,  // 3 AZs are required for Multi-AZ
    NodeType = redshift.NodeType.RA3_XLPLUS,  // must be RA3 node type
    ClusterType = redshift.ClusterType.MULTI_NODE,  // must be MULTI_NODE
    NumberOfNodes = 2,  // must be 2 or more
    MultiAz = true
});
go
var vpc ec2.IVpc


redshift.NewCluster(stack, jsii.String("Cluster"), map[string]interface{}{
	"masterUser": map[string]*string{
		"masterUsername": jsii.String("admin"),
	},
	"vpc": vpc,
	 // 3 AZs are required for Multi-AZ
	"nodeType": redshift.NodeType_RA3_XLPLUS,
	 // must be RA3 node type
	"clusterType": redshift.ClusterType_MULTI_NODE,
	 // must be MULTI_NODE
	"numberOfNodes": jsii.Number(2),
	 // must be 2 or more
	"multiAz": jsii.Boolean(true),
})

Resizing ​

As your data warehousing needs change, it's possible to resize your Redshift cluster. If the cluster was deployed via CDK, it's important to resize it via CDK so the change is registered in the AWS CloudFormation template. There are two types of resize operations:

  • Elastic resize - Number of nodes and node type can be changed, but not at the same time. Elastic resize is the default behavior, as it's a fast operation and typically completes in minutes. Elastic resize is only supported on clusters of the following types:

    • dc1.large (if your cluster is in a VPC)
    • dc1.8xlarge (if your cluster is in a VPC)
    • dc2.large
    • dc2.8xlarge
    • ds2.xlarge
    • ds2.8xlarge
    • ra3.large
    • ra3.xlplus
    • ra3.4xlarge
    • ra3.16xlarge
  • Classic resize - Number of nodes, node type, or both, can be changed. This operation takes longer to complete, but is useful when the resize operation doesn't meet the criteria of an elastic resize. If you prefer classic resizing, you can set the classicResizing flag when creating the cluster.

There are other constraints to be aware of, for example, elastic resizing does not support single-node clusters and there are limits on the number of nodes you can add to a cluster. See the AWS Redshift Documentation and AWS API Documentation for more details.

Maintenance track name ​

When Amazon Redshift releases a new cluster version, your cluster is updated during its maintenance window. You can control whether your cluster is updated to the most recent approved release or to the previous release. See the AWS Redshift Documentation for more details.

To control which cluster version is applied during a maintenance window, set the maintenanceTrackName property for the cluster.

ts
new redshift.Cluster(stack, 'Cluster', {
  masterUser: {
    masterUsername: 'admin',
  },
  vpc,
  maintenanceTrackName: redshift.MaintenanceTrackName.CURRENT,
});
python
redshift.Cluster(stack, "Cluster",
    master_user={
        "master_username": "admin"
    },
    vpc=vpc,
    maintenance_track_name=redshift.MaintenanceTrackName.CURRENT
)
java
Cluster.Builder.create(stack, "Cluster")
        .masterUser(Map.of(
                "masterUsername", "admin"))
        .vpc(vpc)
        .maintenanceTrackName(redshift.getMaintenanceTrackName().getCURRENT())
        .build();
csharp
new redshift.Cluster(stack, "Cluster", new Struct {
    MasterUser = new Struct {
        MasterUsername = "admin"
    },
    Vpc = vpc,
    MaintenanceTrackName = redshift.MaintenanceTrackName.CURRENT
});
go
redshift.NewCluster(stack, jsii.String("Cluster"), map[string]interface{}{
	"masterUser": map[string]*string{
		"masterUsername": jsii.String("admin"),
	},
	"vpc": vpc,
	"maintenanceTrackName": redshift.MaintenanceTrackName_CURRENT,
})

You can specify one of the following MaintenanceTrackName values:

  • CURRENT: Use the most current approved cluster version.
  • TRAILING: Use the cluster version before the current version.

Types ​

NameKindSummary
ClusterConstruct (L2)Create a Redshift cluster a given number of nodes.
ClusterParameterGroupConstruct (L2)A cluster parameter group.
ClusterSubnetGroupConstruct (L2)Class for creating a Redshift cluster subnet group.
DatabaseSecretConstruct (L2)A database secret.
CloudWatchLoggingOptionsStructOptions for CloudWatch logging.
ClusterAttributesStructProperties that describe an existing cluster instance.
ClusterLoggingClassThe logging configuration for a Redshift cluster.
ClusterParameterGroupPropsStructProperties for a parameter group.
ClusterPropsStructProperties for a new database cluster.
ClusterSubnetGroupPropsStructProperties for creating a ClusterSubnetGroup.
ClusterTypeEnumWhat cluster type to use.
ColumnStructA column in a Redshift table.
ColumnEncodingEnumThe compression encoding of a column.
DatabaseOptionsStructProperties for accessing a Redshift database.
DatabaseSecretPropsStructConstruction properties for a DatabaseSecret.
EndpointClassConnection endpoint of a redshift cluster.
IClusterInterfaceCreate a Redshift Cluster with a given number of nodes.
IClusterParameterGroupInterfaceA parameter group.
IClusterSubnetGroupInterfaceInterface for a cluster subnet group.
ITableInterfaceRepresents a table in a Redshift database.
IUserInterfaceRepresents a user in a Redshift database.
LogExportEnumThe type of logs to export.
LoginStructUsername and password combination.
MaintenanceTrackNameEnumThe maintenance track for the cluster.
NodeTypeEnumPossible Node Types to use in the cluster used for defining ClusterProps.nodeType.
ResourceActionEnumThe Amazon Redshift operation.
RotationMultiUserOptionsStructOptions to add the multi user rotation.
S3LoggingOptionsStructOptions for S3 logging.
TableConstructA table in a Redshift cluster.
TableActionEnumAn action that a Redshift user can be granted privilege to perform on a table.
TableAttributesStructA full specification of a Redshift table that can be used to import it fluently into the CDK application.
TableDistStyleEnumThe data distribution style of a table.
TablePropsStructProperties for configuring a Redshift table.
TableSortStyleEnumThe sort style of a table.
UserConstructA user in a Redshift cluster.
UserAttributesStructA full specification of a Redshift user that can be used to import it fluently into the CDK application.
UserPropsStructProperties for configuring a Redshift user.