Connect Confluent CLI to Confluent Cloud Cluster

This topic includes the steps to connect your Confluent CLI instance to a Confluent Cloud cluster. Note that you must have a valid Confluent Cloud user account and an install of the Confluent CLI to complete the following steps:

  1. (Optional) If you’re running Windows Subsystem for Linux (WSL), install xdg-open-wsl.

  2. In your terminal, start autocomplete by entering the following command:

    confluent shell
    
  3. Log in to Confluent Cloud using the confluent login command:

    login --save
    

    Note that with the --save flag, Confluent will log you back in after your login session token expires (if inactive for one hour).

  4. Set the Confluent Cloud environment.

    • Get the environment ID.

      environment list
      

      Your output should resemble:

      Current |    ID       |      Name
      --------+-------------+-----------------
      *       | env-5q432q  | dev
              | env-4q985q  | prod
              | env-2q345q  | jdoe-gcp-env
              | env-9q012q  | jdoe-aws-env
      
    • Set the environment using the ID (<env-id>).

      environment use <env-id>
      

      Your output should resemble:

      Now using env-4q985q as the default (active) environment.
      
  5. Set the cluster to use.

    • Get the cluster ID.

      kafka cluster list
      

      Your output should resemble:

            ID      |       Name        | Provider |   Region    | Durability | Status
      +-------------+-------------------+----------+-------------+------------+--------+
          ekg-rr8v7 | dev-aws-oregon    | aws      | us-west-2   | LOW        | UP
          ekg-q2j96 | prod              | gcp      | us-central1 | LOW        | UP
      
    • Set the cluster using the ID (<cluster-id>). This is the cluster where the commands are run.

      kafka cluster use <cluster-id>
      
  6. Create an API key and secret and save them locally. This is required to produce or consume to your topic.

    From the Confluent CLI, type the following command:

    api-key create --resource <resource-id>
    

    Your output should resemble:

    Save the API key and secret. The secret is not retrievable later.
    +---------+------------------------------------------------------------------+
    | API Key | LD35EM2YJTCTRQRM                                                 |
    | Secret  | 67JImN+9vk+Hj3eaj2/UcwUlbDNlGGC3KAIOy5JNRVSnweumPBUpW31JWZSBeawz |
    +---------+------------------------------------------------------------------+
    
  7. (Optional) Store the API secret locally with confluent api-key store <key> <secret>. When you create an API key with the CLI, it is stored locally. However, when you create an API key using the UI, API, or with the CLI on another machine, the secret is not available for CLI use until you store it. This is required because secrets can’t be retrieved after creation.

    api-key store <api-key> <api-secret> --resource <resource-id>
    
  8. Set the API key to use for the Confluent CLI commands:

    api-key use <api-key>
    

You can now run the Confluent CLI commands against the specified cluster.