List topics using the Amazon CLI
Run the following command, replacing ClusterArn with the Amazon Resource Name (ARN) of your cluster. If you don't have the ARN for your cluster, you can find it by listing all clusters. For more information, see List Amazon MSK clusters.
aws kafka list-topics --cluster-arnClusterArn
The output of this command looks like the following JSON example.
{ "topics": [ { "topicArn": "arn:aws:kafka:us-east-1:123456789012:topic/MyCluster/abcd1234-abcd-dcba-4321-a1b2abcd9f9f-2/MyTopic", "topicName": "MyTopic", "partitionCount": 3, "replicationFactor": 3, "outOfSyncReplicaCount": 0 }, { "topicArn": "arn:aws:kafka:us-east-1:123456789012:topic/MyCluster/abcd1234-abcd-dcba-4321-a1b2abcd9f9f-2/AnotherTopic", "topicName": "AnotherTopic", "partitionCount": 6, "replicationFactor": 3, "outOfSyncReplicaCount": 1 } ] }
Paginating results
If your cluster has many topics, you can use pagination to retrieve results in smaller batches. Use the --max-results parameter to specify the maximum number of topics to return, and use the --next-token parameter to retrieve the next page of results.
aws kafka list-topics --cluster-arnClusterArn--max-results 10
If there are more results available, the response includes a nextToken value. Use this token to retrieve the next page of results.
aws kafka list-topics --cluster-arnClusterArn--max-results 10 --next-tokenNextToken
Filtering topics by name
You can filter the list of topics by specifying a prefix using the --topic-name-filter parameter. This returns only topics whose names start with the specified prefix.
aws kafka list-topics --cluster-arnClusterArn--topic-name-filter "prod-"
This command returns only topics whose names start with prod-, such as prod-orders or prod-inventory.