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 to complete the following steps:

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

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

    confluent login --save

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

  3. Set the Confluent Cloud environment.

    • Get the environment ID.

      confluent environment list

      Your output should resemble:

           ID    |      Name
        * a-542  | dev
          a-4985 | prod
          a-2345 | jdoe-gcp-env
          a-9012 | jdoe-aws-env
    • Set the environment using the ID (<env-id>).

      confluent environment use <env-id>

      Your output should resemble:

      Now using a-4985 as the default (active) environment.
  4. Set the cluster to use.

    • Get the cluster ID.

      confluent 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.

      confluent kafka cluster use <cluster-id>
  5. 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:

    confluent 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 |
  6. (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.

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

    confluent api-key use <api-key> --resource <resource-id>

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