This page requires JavaScript to display.
M
Unpacking...
← Cloud Platforms
Cloud Platforms

Amazon MSK for Data Engineers

Managed Kafka options, bootstrap brokers and authentication, IAM producers and Spark consumers, MSK Connect, sizing and operations.

Contents
1. What Amazon MSK Is 2. Connecting & Authentication 3. MSK Connect 4. Sizing & Operations 5. Common Interview Questions

1. What Amazon MSK Is

Amazon Managed Streaming for Apache Kafka (MSK) runs Apache Kafka for you: brokers, storage, patching and recovery across availability zones. Your producers, consumers and tools use the standard Kafka APIs, so everything in the Kafka guide applies.

OptionNotes
MSK provisioned (standard brokers)You choose broker size and count; EBS storage with optional tiered storage
MSK provisioned (Express brokers)Higher throughput per broker, faster scaling and recovery, storage managed for you
MSK ServerlessNo broker sizing; capacity scales automatically; IAM authentication only
MSK ConnectManaged Kafka Connect workers for source and sink connectors
MSK ReplicatorManaged replication between MSK clusters (cross-region DR, migration)

2. Connecting & Authentication

aws kafka list-clusters-v2 --query "ClusterInfoList[].{name:ClusterName, arn:ClusterArn}"
aws kafka get-bootstrap-brokers --cluster-arn arn:aws:kafka:ap-south-1:111122223333:cluster/txn-cluster/abc-123
AuthenticationPortNotes
IAM access control9098IAM policies grant actions on clusters, topics and groups; no passwords
SASL/SCRAM9096Username/password stored in Secrets Manager
Mutual TLS9094Client certificates from AWS Private CA
Plaintext9092Avoid outside development
# Python producer with IAM auth: pip install confluent-kafka aws-msk-iam-sasl-signer-python
import json
from confluent_kafka import Producer
from aws_msk_iam_sasl_signer import MSKAuthTokenProvider

REGION = "ap-south-1"

def oauth_cb(oauth_config):
    token, expiry_ms = MSKAuthTokenProvider.generate_auth_token(REGION)
    return token, expiry_ms / 1000                         # seconds

producer = Producer({
    "bootstrap.servers": "b-1.txncluster.abc123.c2.kafka.ap-south-1.amazonaws.com:9098",
    "security.protocol": "SASL_SSL",
    "sasl.mechanisms": "OAUTHBEARER",
    "oauth_cb": oauth_cb,
    "acks": "all",
    "enable.idempotence": True,
})
producer.produce("txn.events", key="ACC1", value=json.dumps({"txn_id": "T1", "amount": 250}))
producer.flush()
# Spark Structured Streaming reading MSK with IAM (needs the aws-msk-iam-auth JAR on the classpath)
stream = (spark.readStream.format("kafka")
    .option("kafka.bootstrap.servers", BOOTSTRAP)
    .option("subscribe", "txn.events")
    .option("kafka.security.protocol", "SASL_SSL")
    .option("kafka.sasl.mechanism", "AWS_MSK_IAM")
    .option("kafka.sasl.jaas.config", "software.amazon.msk.auth.iam.IAMLoginModule required;")
    .option("kafka.sasl.client.callback.handler.class",
            "software.amazon.msk.auth.iam.IAMClientCallbackHandler")
    .option("startingOffsets", "latest")
    .load())
{
  "Version": "2012-10-17",
  "Statement": [
    { "Effect": "Allow", "Action": ["kafka-cluster:Connect", "kafka-cluster:DescribeCluster"],
      "Resource": "arn:aws:kafka:ap-south-1:111122223333:cluster/txn-cluster/*" },
    { "Effect": "Allow", "Action": ["kafka-cluster:ReadData", "kafka-cluster:DescribeTopic"],
      "Resource": "arn:aws:kafka:ap-south-1:111122223333:topic/txn-cluster/*/txn.events" },
    { "Effect": "Allow", "Action": ["kafka-cluster:AlterGroup", "kafka-cluster:DescribeGroup"],
      "Resource": "arn:aws:kafka:ap-south-1:111122223333:group/txn-cluster/*/fraud-scoring" }
  ]
}

3. MSK Connect

MSK Connect runs Kafka Connect connectors (packaged as custom plugins from S3) with autoscaling workers. Typical data-engineering connectors:

ConnectorDirectionUse
Debezium (MySQL/PostgreSQL/SQL Server)SourceCDC from databases into topics
S3 sink (e.g. Confluent S3 sink)SinkLand topics in S3 as Parquet/JSON partitioned by time
Iceberg sinkSinkWrite topics into Iceberg tables
JDBC / OpenSearch sinksSinkServing databases and search indexes

4. Sizing & Operations

5. Common Interview Questions

QuestionShort answer
MSK vs Kinesis?MSK gives open Kafka APIs and ecosystem (Connect, Streams, Flink), portability and fine control; Kinesis is simpler and fully AWS-native
MSK provisioned vs Serverless?Provisioned: you size brokers, any auth, more tuning. Serverless: automatic capacity, IAM auth only, simpler for variable workloads
How do clients authenticate to MSK?IAM (port 9098), SASL/SCRAM with Secrets Manager (9096), or mutual TLS (9094)
How do you avoid data loss on MSK?Replication factor 3 across AZs, min.insync.replicas 2, acks=all, idempotent producers
How do you get CDC data into Kafka on AWS?Debezium source connectors on MSK Connect (or DMS with a Kafka target)