Skip to content
GitHubXDiscordRSS

Cluster

Learn how to create, update, and manage AWS MSK Clusters using Alchemy Cloud Control.

The Cluster resource lets you manage AWS MSK Clusters for running Apache Kafka in a fully managed environment.

Create a basic MSK Cluster with required properties and one optional property for logging:

import AWS from "alchemy/aws/control";
const kafkaCluster = await AWS.MSK.Cluster("basicKafkaCluster", {
KafkaVersion: "2.8.0",
NumberOfBrokerNodes: 3,
BrokerNodeGroupInfo: {
InstanceType: "kafka.m5.large",
ClientSubnets: ["subnet-12345678", "subnet-87654321"],
SecurityGroups: ["sg-0abcdef1234567890"]
},
LoggingInfo: {
BrokerLogs: {
CloudWatchLogs: {
Enabled: true,
LogGroup: "kafka-logs",
LogStream: "broker-logs"
}
}
}
});

Configure an MSK Cluster with encryption and enhanced monitoring settings:

const secureKafkaCluster = await AWS.MSK.Cluster("secureKafkaCluster", {
KafkaVersion: "2.8.0",
NumberOfBrokerNodes: 3,
BrokerNodeGroupInfo: {
InstanceType: "kafka.m5.large",
ClientSubnets: ["subnet-12345678", "subnet-87654321"],
SecurityGroups: ["sg-0abcdef1234567890"]
},
EncryptionInfo: {
EncryptionAtRest: {
DataVolumeKmsKeyId: "arn:aws:kms:us-west-2:123456789012:key/abcd1234-56ef-78gh-90ij-klmnopqrstuv"
}
},
EnhancedMonitoring: "PER_TOPIC_PER_BROKER"
});

Custom Configuration with Client Authentication

Section titled “Custom Configuration with Client Authentication”

Create an MSK Cluster with client authentication and configuration settings:

const authenticatedKafkaCluster = await AWS.MSK.Cluster("authenticatedKafkaCluster", {
KafkaVersion: "2.8.0",
NumberOfBrokerNodes: 3,
BrokerNodeGroupInfo: {
InstanceType: "kafka.m5.large",
ClientSubnets: ["subnet-12345678", "subnet-87654321"],
SecurityGroups: ["sg-0abcdef1234567890"]
},
ClientAuthentication: {
Sasl: {
Scram: {
Enabled: true
}
},
Tls: {
Enabled: true
}
},
ConfigurationInfo: {
Arn: "arn:aws:msk:us-west-2:123456789012:configuration/my-configuration",
Revision: 1
}
});

Create an MSK Cluster with tags for better resource management:

const taggedKafkaCluster = await AWS.MSK.Cluster("taggedKafkaCluster", {
KafkaVersion: "2.8.0",
NumberOfBrokerNodes: 3,
BrokerNodeGroupInfo: {
InstanceType: "kafka.m5.large",
ClientSubnets: ["subnet-12345678", "subnet-87654321"],
SecurityGroups: ["sg-0abcdef1234567890"]
},
Tags: {
Environment: "Production",
Project: "KafkaService"
}
});