> **Experimental**
>
> `@aws-cdk/aws-msk-alpha` is an [**experimental**](/stability) (alpha) package: its API may change in any release, without a major version bump.
# Cluster

Create a MSK Cluster.

Extends: Construct › Resource › ClusterBase › Cluster
Implements: ICluster, IResource, IConnectable, IEnvironmentAware, IConstruct, IDependable

- Stability: [Experimental](/cdk/api/stability.html)
- CloudFormation: [`AWS::MSK::Cluster`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-msk-cluster.html)
- L1 type: [`CfnCluster`](/cdk/api/v2/docs/aws-cdk-lib.aws_msk.CfnCluster.html)
- Source: [`lib/cluster.ts`](https://github.com/aws/aws-cdk/blob/v2.274.0-alpha.0/packages/@aws-cdk/aws-msk-alpha/lib/cluster.ts#L469)

## Example

```ts
declare const vpc: ec2.Vpc;
const cluster = new msk.Cluster(this, 'cluster', {
  clusterName: 'myCluster',
  kafkaVersion: msk.KafkaVersion.V4_1_X_KRAFT,
  vpc,
  encryptionInTransit: {
    clientBroker: msk.ClientBrokerEncryption.TLS,
  },
  clientAuthentication: msk.ClientAuthentication.sasl({
    scram: true,
  }),
});
```

## Initializer

```ts
new Cluster(scope: Construct, id: string, props: ClusterProps)
```

## Construct Props

- `brokerType`: [BrokerType](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.BrokerType.html) = BrokerType.STANDARD — The broker type for the cluster.

  When set to EXPRESS, the cluster will be created with Express Brokers.
  When this is set to EXPRESS, instanceType must also be specified.

- `clientAuthentication`: [ClientAuthentication](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.ClientAuthentication.html) = disabled — Configuration properties for client authentication.

  MSK supports using private TLS certificates or SASL/SCRAM to authenticate the identity of clients.

- `clusterName`: string (required) — The physical name of the cluster.

- `configurationInfo`: [ClusterConfigurationInfo](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.ClusterConfigurationInfo.html) = none — The Amazon MSK configuration to use for the cluster.

- `ebsStorageInfo`: [EbsStorageInfo](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.EbsStorageInfo.html) — Information about storage volumes attached to MSK broker nodes.

  **Default:** 1000 GiB EBS volume

- `encryptionInTransit`: [EncryptionInTransitConfig](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.EncryptionInTransitConfig.html) = enabled — Config details for encryption in transit.

- `instanceType`: [InstanceType](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.InstanceType.html) = kafka.m5.large — The EC2 instance type that you want Amazon MSK to use when it creates your brokers.

- `kafkaVersion`: [KafkaVersion](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.KafkaVersion.html) (required) — The version of Apache Kafka.

- `logging`: [BrokerLogging](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.BrokerLogging.html) = disabled — Configure your MSK cluster to send broker logs to different destination types.

- `monitoring`: [MonitoringConfiguration](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.MonitoringConfiguration.html) — Cluster monitoring configuration.

  **Default:** DEFAULT monitoring level

- `numberOfBrokerNodes`: number = 1 — Number of Apache Kafka brokers deployed in each Availability Zone.

- `removalPolicy`: [RemovalPolicy](/cdk/api/v2/docs/aws-cdk-lib.RemovalPolicy.html) = RemovalPolicy.RETAIN — What to do when this resource is deleted from a stack.

- `securityGroups`: [ISecurityGroup](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.ISecurityGroup.html)[] — The AWS security groups to associate with the elastic network interfaces in order to specify who can connect to and communicate with the Amazon MSK cluster.

  **Default:** create new security group

- `storageMode`: [StorageMode](/cdk/api/v2/docs/@aws-cdk_aws-msk-alpha.StorageMode.html) = StorageMode.LOCAL — This controls storage mode for supported storage tiers.

- `vpc`: [IVpc](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.IVpc.html) (required) — Defines the virtual networking environment for this cluster.

  Must have at least 2 subnets in two different AZs.

- `vpcSubnets`: [SubnetSelection](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.SubnetSelection.html) — Where to place the nodes within the VPC.

  **Default:** the Vpc default strategy if not specified.

  Amazon MSK distributes the broker nodes evenly across the subnets that you specify.
  The subnets that you specify must be in distinct Availability Zones.
  Client subnets can't be in Availability Zone us-east-1e.

## Properties

- `bootstrapBrokers`: string (required) — Get the list of brokers that a client application can use to bootstrap.

  Uses a Custom Resource to make an API call to `getBootstrapBrokers` using the Javascript SDK

- `bootstrapBrokersSaslIam`: string (required) — Get the list of brokers that a SASL/IAM authenticated client application can use to bootstrap.

  Uses a Custom Resource to make an API call to `getBootstrapBrokers` using the Javascript SDK

- `bootstrapBrokersSaslScram`: string (required) — Get the list of brokers that a SASL/SCRAM authenticated client application can use to bootstrap.

  Uses a Custom Resource to make an API call to `getBootstrapBrokers` using the Javascript SDK

- `bootstrapBrokersTls`: string (required) — Get the list of brokers that a TLS authenticated client application can use to bootstrap.

  Uses a Custom Resource to make an API call to `getBootstrapBrokers` using the Javascript SDK

- `clusterArn`: string (required) — The ARN of cluster.

- `clusterName`: string (required) — The physical name of the cluster.

- `connections`: [Connections](/cdk/api/v2/docs/aws-cdk-lib.aws_ec2.Connections.html) (required) — Manages connections for the cluster.

- `env`: [ResourceEnvironment](/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) (required) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `node`: [Node](/cdk/api/v2/docs/constructs.Node.html) (required) — The tree node.

- `PROPERTY_INJECTION_ID`: string (required) (static) — Uniquely identifies this class.

- `saslScramAuthenticationKey`: [IKey](/cdk/api/v2/docs/aws-cdk-lib.aws_kms.IKey.html) — Key used to encrypt SASL/SCRAM users.

- `stack`: [Stack](/cdk/api/v2/docs/aws-cdk-lib.Stack.html) (required) — The stack in which this resource is defined.

- `zookeeperConnectionString`: string (required) — Get the ZooKeeper Connection string.

  Uses a Custom Resource to make an API call to `describeCluster` using the Javascript SDK

- `zookeeperConnectionStringTls`: string (required) — Get the ZooKeeper Connection string for a TLS enabled cluster.

  Uses a Custom Resource to make an API call to `describeCluster` using the Javascript SDK

## Methods

- `addUser(...usernames: string[]): void` — A list of usersnames to register with the cluster.

  The password will automatically be generated using Secrets
  Manager and the { username, password } JSON object stored in Secrets Manager as `AmazonMSK_username`.

  Must be using the SASL/SCRAM authentication mechanism.

  **Parameters**

  - `usernames` — - username(s) to register with the cluster.

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `fromClusterArn(scope: Construct, id: string, clusterArn: string): ICluster` (static) — Reference an existing cluster, defined outside of the CDK code, by name.

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
