title: How to connect to MSK with SASL/SCRAM using Java?
body: <p>I'm trying to figure out how to create a working Kafka producer against an AWS MSK cluster. The cluster has TLS and SASL/SCRAM enabled. This is my first time using Kafka and the documentation on this is rather slim. The code that I currently have, which works against an unencrypted local cluster, is:</p>
  <pre><code>Properties props = new Properties();
  props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, serverBootstrap);
  props.put(ProducerConfig.CLIENT_ID_CONFIG, CLIENT_ID);
  props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
  props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
  producer = new KafkaProducer&lt;&gt;(props);
  </code></pre>
  <p>I have String typed variables <code>username</code> and <code>password</code>, which have been pulled from AWS Secrets Manager and contain the username and password for the cluster. What additional properties do I need to specify?</p>
  <p>The docs by AWS and on the Kafka website are all about generating JAAS and truststore files on the local file system which would contain the secrets:</p>
  <p><a href="https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/msk/latest/developerguide/msk-password.html</a></p>
  <p>This is a non-starter for me. Basically, I need to create a generic Docker image that would be given as an environment variable the name of the secret in AWS Secrets Manager that will contain the username and password for the cluster.</p>
  <p>I would assume this to be how people would authenticate to a cluster by default, but there are no instructions describing how to do this. The reason I'm not using the MSK IAM integration is that we will probably hit the 3000 connections per broker limit.</p>