Ask Your Question
3

How can one retrieve the list of bootstrap servers for a pre-existing cluster using AWS CDK MSK?

asked 2022-10-22 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-12-17 03:00:00 +0000

djk gravatar image

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.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-10-22 11:00:00 +0000

Seen: 10 times

Last updated: Dec 17 '21