Kafka clients outside AWS cannot connect to an Amazon MSK cluster
Your error
Connection to node -1 (<broker-host>/<ip>:9098) could not be established. Node may not be available.2 more lines it can showFix it fast
Most common cause, 1 of 3Public access is still off for the cluster
Bring the cluster in line with the conditions first (a cluster created with encryption within the cluster turned off can never get public access).
aws kafka update-connectivity --cluster-arn <cluster-arn> \
--current-version K3AEGXETSR30VB \
--connectivity-info '{"PublicAccess": {"Type": "SERVICE_PROVIDED_EIPS"}}'
aws kafka describe-cluster-operation --cluster-operation-arn <cluster-operation-arn>Short answer
Amazon MSK brokers answer only inside their VPC until you turn on public access, which needs an existing cluster, public subnets, client authentication on and plaintext off. Outside clients must then use the public bootstrap string on port 9194, 9196 or 9198, and the security group and network ACL must allow their IP. Applies to MSK Provisioned, Kafka 2.6.0+.
Which cause do you have?
Ask MSK whether public access is on and which bootstrap strings the cluster offers. Public strings appear only once public access is on.
aws kafka describe-cluster --cluster-arn arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-5678-90ab-cdef-1234567890ab-2 \
--query 'ClusterInfo.BrokerNodeGroupInfo.ConnectivityInfo.PublicAccess.Type'
aws kafka get-bootstrap-brokers --cluster-arn arn:aws:kafka:us-east-1:123456789012:cluster/my-cluster/abcd1234-5678-90ab-cdef-1234567890ab-2Then find the line you see in this list and open its fix:
- 1Public access is still off for the cluster
PublicAccess.Type is DISABLED, and get-bootstrap-brokers returns no BootstrapBrokerStringPublic* field - 2The client still uses the bootstrap string meant for inside AWS
bootstrap.servers ends in port 9092, 9094, 9096 or 9098 while the client runs outside the VPC - 3The security group or network ACL does not let your IP reach the public ports
Public access is on and the public string is in use, but a TCP test to port 9194, 9196 or 9198 hangs from the client
What does the error look like?
Connection to node -1 (<broker-host>/<ip>:9098) could not be established. Node may not be available.Bootstrap broker ... disconnectedThe Kafka client works from an EC2 instance in the VPC but times out from a laptop or another cloud
Cause 1 of 3
Public access is still off for the cluster
You seePublicAccess.Type is DISABLED, and get-bootstrap-brokers returns no BootstrapBrokerStringPublic* field
Check
An outside client cannot connect to Amazon MSK while public access is DISABLED, because the brokers then have only network interfaces inside the cluster's VPC. MSK refuses public access at creation time, so every cluster starts this way. Turning it on also requires public subnets for the brokers, unauthenticated access off with SASL/IAM, SASL/SCRAM or mTLS on, encryption within the cluster on, and plaintext between clients and brokers off.
aws kafka describe-cluster --cluster-arn <cluster-arn> \
--query 'ClusterInfo.{version: CurrentVersion, unauth: ClientAuthentication.Unauthenticated.Enabled, clientBroker: EncryptionInfo.EncryptionInTransit.ClientBroker, inCluster: EncryptionInfo.EncryptionInTransit.InCluster, subnets: BrokerNodeGroupInfo.ClientSubnets}'Fix
Bring the cluster in line with the conditions first (a cluster created with encryption within the cluster turned off can never get public access). For SASL/SCRAM or mTLS, set Kafka ACLs and allow.everyone.if.no.acl.found=false before you open it. Then switch public access on with the cluster's current version.
aws kafka update-connectivity --cluster-arn <cluster-arn> \
--current-version K3AEGXETSR30VB \
--connectivity-info '{"PublicAccess": {"Type": "SERVICE_PROVIDED_EIPS"}}'
aws kafka describe-cluster-operation --cluster-operation-arn <cluster-operation-arn>Verify
describe-cluster-operation reaches UPDATE_COMPLETE, and PublicAccess.Type reads SERVICE_PROVIDED_EIPS.
aws kafka describe-cluster --cluster-arn <cluster-arn> --query 'ClusterInfo.BrokerNodeGroupInfo.ConnectivityInfo.PublicAccess.Type'Confirmed by docs.aws.amazon.com
Cause 2 of 3
The client still uses the bootstrap string meant for inside AWS
You seebootstrap.servers ends in port 9092, 9094, 9096 or 9098 while the client runs outside the VPC
Check
A cluster with public access has two sets of bootstrap brokers, and an outside client that keeps the in-VPC set cannot get in. The in-VPC ports are 9094 (TLS), 9096 (SASL/SCRAM) and 9098 (IAM); the public ones are 9194, 9196 and 9198. Plaintext on 9092 has no public form, since public access needs plaintext off.
aws kafka get-bootstrap-brokers --cluster-arn <cluster-arn> \
--query '{iam: BootstrapBrokerStringPublicSaslIam, scram: BootstrapBrokerStringPublicSaslScram, tls: BootstrapBrokerStringPublicTls}'
grep bootstrap.servers client.propertiesFix
Copy the public string for your authentication method into the outside client's bootstrap.servers, and keep the in-VPC string for clients that run inside AWS.
# client.properties used outside AWS (IAM access control)
bootstrap.servers=<value of BootstrapBrokerStringPublicSaslIam>Verify
A topic listing through the public string works from the outside machine.
bin/kafka-topics.sh --bootstrap-server "$PUBLIC_BOOTSTRAP" --command-config client.properties --listConfirmed by docs.aws.amazon.com
Cause 3 of 3
The security group or network ACL does not let your IP reach the public ports
You seePublic access is on and the public string is in use, but a TCP test to port 9194, 9196 or 9198 hangs from the client
Check
Turning on public access does not open the cluster's security group. Its inbound rules must allow the client's public IP on the public broker port, and AWS also asks you to confirm that its outbound rules let traffic out. The VPC network ACL is stateless, so it needs the inbound port for your IP and an outbound rule back to your IP as well.
timeout 5 bash -c '</dev/tcp/<public-broker-host>/9198' && echo "9198 reachable"
aws ec2 describe-security-groups --group-ids sg-0123456789abcdef0 \
--query 'SecurityGroups[].IpPermissions[?FromPort==`9198`]'Fix
Add an inbound rule for the public port from your own address only, as AWS advises keeping these rules tight, and add matching network ACL entries if the brokers' subnets use a custom ACL.
aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 \
--protocol tcp --port 9198 --cidr 198.51.100.7/32Verify
The TCP test reports the port reachable and the Kafka client connects.
timeout 5 bash -c '</dev/tcp/<public-broker-host>/9198' && echo "9198 reachable"Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Decide at design time whether outside clients need the cluster; if they do, create it with in-cluster encryption on, because that setting cannot be changed later and public access depends on it.
- Keep two client configs, one with the in-VPC bootstrap string and one with the public string, and name them after where they run.
- Allow the public broker ports only from known client addresses, and review that list whenever a client's egress IP changes.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: Dispatch Pro, Raheeb, Loade Driver.