Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To retrieve the list of bootstrap servers for a pre-existing cluster using AWS CDK MSK, you can use the AWS SDK and the describeCluster() method to obtain the cluster configuration. Then, you can access the bootstrapBrokers property to retrieve the list of bootstrap servers.

Here's an example TypeScript code snippet that shows how to obtain the bootstrap server in CDK:

import * as cdk from 'aws-cdk-lib';
import * as msk from 'aws-cdk-lib/aws-msk';

const app = new cdk.App();

const clusterArn = 'arn:aws:kafka:us-west-2:123456789012:cluster/my-cluster/abcdefg-1234-5678-90ab-cdefghijklmn';
const mskCluster = msk.Cluster.fromClusterArn(app, 'mskCluster', clusterArn);

const describeClusterResult = await new AWS.Kafka().describeCluster({ ClusterArn: clusterArn }).promise();
const bootstrapServers = describeClusterResult.ClusterInfo.BootstrapBrokers.join(',');

In this example:

  • We import the required AWS CDK and MSK libraries.
  • We create an instance of the Cluster class using the fromClusterArn() method.
  • We use the AWS SDK to obtain the cluster configuration using the describeCluster() method and passing the cluster ARN as a parameter.
  • Finally, we retrieve and join the bootstrap servers list from the describeCluster() result, and assign it to the bootstrapServers variable.