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:
Cluster
class using the fromClusterArn()
method.describeCluster()
method and passing the cluster ARN as a parameter.describeCluster()
result, and assign it to the bootstrapServers
variable.