Skip to content
v2.274.0

Experimental

@aws-cdk/aws-msk-alpha is an experimental (alpha) package: its API may change in any release, without a major version bump.

Cluster L2 construct ​

Create a MSK Cluster.

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,
  }),
});
python
# vpc: ec2.Vpc

cluster = msk.Cluster(self, "cluster",
    cluster_name="myCluster",
    kafka_version=msk.KafkaVersion.V4_1_X_KRAFT,
    vpc=vpc,
    encryption_in_transit=msk.EncryptionInTransitConfig(
        client_broker=msk.ClientBrokerEncryption.TLS
    ),
    client_authentication=msk.ClientAuthentication.sasl(
        scram=True
    )
)
java
Vpc vpc;

Cluster cluster = Cluster.Builder.create(this, "cluster")
        .clusterName("myCluster")
        .kafkaVersion(KafkaVersion.V4_1_X_KRAFT)
        .vpc(vpc)
        .encryptionInTransit(EncryptionInTransitConfig.builder()
                .clientBroker(ClientBrokerEncryption.TLS)
                .build())
        .clientAuthentication(ClientAuthentication.sasl(SaslAuthProps.builder()
                .scram(true)
                .build()))
        .build();
csharp
// Install: dotnet add package Amazon.CDK.AWS.MSK.Alpha
Vpc vpc;

var cluster = new Cluster(this, "cluster", new ClusterProps {
    ClusterName = "myCluster",
    KafkaVersion = KafkaVersion.V4_1_X_KRAFT,
    Vpc = vpc,
    EncryptionInTransit = new EncryptionInTransitConfig {
        ClientBroker = ClientBrokerEncryption.TLS
    },
    ClientAuthentication = ClientAuthentication.Sasl(new SaslAuthProps {
        Scram = true
    })
});
go
// Install: go get github.com/aws/aws-cdk-go/awscdkmskalpha/v2
var vpc Vpc

cluster := msk.NewCluster(this, jsii.String("cluster"), &ClusterProps{
	ClusterName: jsii.String("myCluster"),
	KafkaVersion: msk.KafkaVersion_V4_1_X_KRAFT(),
	Vpc: Vpc,
	EncryptionInTransit: &EncryptionInTransitConfig{
		ClientBroker: msk.ClientBrokerEncryption_TLS,
	},
	ClientAuthentication: msk.ClientAuthentication_Sasl(&SaslAuthProps{
		Scram: jsii.Boolean(true),
	}),
})

Initializer ​

ts
new Cluster(scope: Construct, id: string, props: ClusterProps)
python
Cluster(scope: Construct, id: str, props: ClusterProps)
java
new Cluster(Construct scope, String id, ClusterProps props)
csharp
new Cluster(Construct scope, string id, ClusterProps props)
go
NewCluster(Scope Construct, Id *string, Props ClusterProps)

Construct Props ​

brokerTypeBrokerTypebroker_typeBrokerTypebrokerTypeBrokerTypeBrokerTypeBrokerTypeBrokerTypeBrokerType= 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.

clientAuthenticationClientAuthenticationclient_authenticationClientAuthenticationclientAuthenticationClientAuthenticationClientAuthenticationClientAuthenticationClientAuthenticationClientAuthentication= disabled#
Configuration properties for client authentication.

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

clusterNamestringcluster_namestrclusterNameStringClusterNamestringClusterName*stringrequired#
The physical name of the cluster.
configurationInfoClusterConfigurationInfoconfiguration_infoClusterConfigurationInfoconfigurationInfoClusterConfigurationInfoConfigurationInfoClusterConfigurationInfoConfigurationInfoClusterConfigurationInfo= none#
The Amazon MSK configuration to use for the cluster.
ebsStorageInfoEbsStorageInfoebs_storage_infoEbsStorageInfoebsStorageInfoEbsStorageInfoEbsStorageInfoEbsStorageInfoEbsStorageInfoEbsStorageInfo#
Information about storage volumes attached to MSK broker nodes.

Default: 1000 GiB EBS volume

encryptionInTransitEncryptionInTransitConfigencryption_in_transitEncryptionInTransitConfigencryptionInTransitEncryptionInTransitConfigEncryptionInTransitEncryptionInTransitConfigEncryptionInTransitEncryptionInTransitConfig= enabled#
Config details for encryption in transit.
instanceTypeInstanceTypeinstance_typeInstanceTypeinstanceTypeInstanceTypeInstanceTypeInstanceTypeInstanceTypeInstanceType= kafka.m5.large#
The EC2 instance type that you want Amazon MSK to use when it creates your brokers.
kafkaVersionKafkaVersionkafka_versionKafkaVersionkafkaVersionKafkaVersionKafkaVersionKafkaVersionKafkaVersionKafkaVersionrequired#
The version of Apache Kafka.
loggingBrokerLoggingloggingBrokerLoggingloggingBrokerLoggingLoggingBrokerLoggingLoggingBrokerLogging= disabled#
Configure your MSK cluster to send broker logs to different destination types.
Cluster monitoring configuration.

Default: DEFAULT monitoring level

numberOfBrokerNodesnumbernumber_of_broker_nodesint | floatnumberOfBrokerNodesNumberNumberOfBrokerNodesdoubleNumberOfBrokerNodes*float64= 1#
Number of Apache Kafka brokers deployed in each Availability Zone.
removalPolicyRemovalPolicyremoval_policyRemovalPolicyremovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicyRemovalPolicy= RemovalPolicy.RETAIN#
What to do when this resource is deleted from a stack.
securityGroupsISecurityGroup[]security_groupstyping.List[ISecurityGroup]securityGroupsList<ISecurityGroup>SecurityGroupsISecurityGroup[]SecurityGroups*[]ISecurityGroup#
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

storageModeStorageModestorage_modeStorageModestorageModeStorageModeStorageModeStorageModeStorageModeStorageMode= StorageMode.LOCAL#
This controls storage mode for supported storage tiers.
vpcIVpcvpcIVpcvpcIVpcVpcIVpcVpcIVpcrequired#
Defines the virtual networking environment for this cluster.

Must have at least 2 subnets in two different AZs.

vpcSubnetsSubnetSelectionvpc_subnetsSubnetSelectionvpcSubnetsSubnetSelectionVpcSubnetsSubnetSelectionVpcSubnetsSubnetSelection#
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 ​

bootstrapBrokersstringbootstrap_brokersstrbootstrapBrokersStringBootstrapBrokersstringBootstrapBrokers*stringrequired#
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

bootstrapBrokersSaslIamstringbootstrap_brokers_sasl_iamstrbootstrapBrokersSaslIamStringBootstrapBrokersSaslIamstringBootstrapBrokersSaslIam*stringrequired#
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

bootstrapBrokersSaslScramstringbootstrap_brokers_sasl_scramstrbootstrapBrokersSaslScramStringBootstrapBrokersSaslScramstringBootstrapBrokersSaslScram*stringrequired#
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

bootstrapBrokersTlsstringbootstrap_brokers_tlsstrbootstrapBrokersTlsStringBootstrapBrokersTlsstringBootstrapBrokersTls*stringrequired#
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

clusterArnstringcluster_arnstrclusterArnStringClusterArnstringClusterArn*stringrequired#
The ARN of cluster.
clusterNamestringcluster_namestrclusterNameStringClusterNamestringClusterName*stringrequired#
The physical name of the cluster.
connectionsConnectionsconnectionsConnectionsconnectionsConnectionsConnectionsConnectionsConnectionsConnectionsrequired#
Manages connections for the cluster.
The environment this resource belongs to.
notes

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.

nodeNodenodeNodenodeNodeNodeNodeNodeNoderequired#
The tree node.
PROPERTY_INJECTION_IDstringproperty_injection_idstrPROPERTY_INJECTION_IDStringPROPERTY_INJECTION_IDstringPROPERTY_INJECTION_ID*stringrequiredstatic#
Uniquely identifies this class.
saslScramAuthenticationKeyIKeysasl_scram_authentication_keyIKeysaslScramAuthenticationKeyIKeySaslScramAuthenticationKeyIKeySaslScramAuthenticationKeyIKey#
Key used to encrypt SASL/SCRAM users.
stackStackstackStackstackStackStackStackStackStackrequired#
The stack in which this resource is defined.
zookeeperConnectionStringstringzookeeper_connection_stringstrzookeeperConnectionStringStringZookeeperConnectionStringstringZookeeperConnectionString*stringrequired#
Get the ZooKeeper Connection string.

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

zookeeperConnectionStringTlsstringzookeeper_connection_string_tlsstrzookeeperConnectionStringTlsStringZookeeperConnectionStringTlsstringZookeeperConnectionStringTls*stringrequired#
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[]): voiddef add_user(self, usernames: str) -> Nonepublic void addUser(String usernames)public void AddUser(string usernames)func AddUser(Usernames *string)#
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.

1 parameter

Parameters

  • usernamesusernamesusernamesusernamesUsernames — - username(s) to register with the cluster.
applyCrossStackReferenceStrength(strength: ReferenceStrength): voiddef apply_cross_stack_reference_strength(self, strength: ReferenceStrength) -> Nonepublic void applyCrossStackReferenceStrength(ReferenceStrength strength)public void ApplyCrossStackReferenceStrength(ReferenceStrength strength)func ApplyCrossStackReferenceStrength(Strength ReferenceStrength)#
Override the cross-stack reference strength for this resource.
notes · 1 parameter

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

  • strengthstrengthstrengthstrengthStrength — - The reference strength to use for this resource.
applyRemovalPolicy(policy: RemovalPolicy): voiddef apply_removal_policy(self, policy: RemovalPolicy) -> Nonepublic void applyRemovalPolicy(RemovalPolicy policy)public void ApplyRemovalPolicy(RemovalPolicy policy)func ApplyRemovalPolicy(Policy RemovalPolicy)#
Apply the given removal policy to this resource.
notes

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@staticmethod def from_cluster_arn(scope: Construct, id: str, cluster_arn: str) -> IClusterpublic static ICluster fromClusterArn(Construct scope, String id, String clusterArn)public static ICluster FromClusterArn(Construct scope, string id, string clusterArn)func FromClusterArn(Scope Construct, Id *string, ClusterArn *string) IClusterstatic#
Reference an existing cluster, defined outside of the CDK code, by name.
isConstruct(x: any): boolean@staticmethod def is_construct(x: Any) -> boolpublic static Boolean isConstruct(Object x)public static bool IsConstruct(object x)func IsConstruct(X interface{}) *boolstatic#
Checks if `x` is a construct.
notes · 1 parameter · returns

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

  • xxxxX — Any object.

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

isOwnedResource(construct: IConstruct): boolean@staticmethod def is_owned_resource(construct: IConstruct) -> boolpublic static Boolean isOwnedResource(IConstruct construct)public static bool IsOwnedResource(IConstruct construct)func IsOwnedResource(Construct IConstruct) *boolstatic#
Returns true if the construct was created by CDK, and false otherwise.
isResource(construct: IConstruct): boolean@staticmethod def is_resource(construct: IConstruct) -> boolpublic static Boolean isResource(IConstruct construct)public static bool IsResource(IConstruct construct)func IsResource(Construct IConstruct) *boolstatic#
Check whether the given construct is a Resource.
toString(): stringdef to_string(self, ) -> strpublic String toString()public string ToString()func ToString() *string#
Returns a string representation of this construct.
with(...mixins: IMixin[]): IConstructdef with(self, mixins: IMixin) -> IConstructpublic IConstruct with(IMixin mixins)public IConstruct With(IMixin mixins)func 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.