Setting the environment for a project

Environments are sets of user-defined variables that can be substituted into templates in your SSB resources. Environments are like configuration files for your projects that adapt it to be used in a specific environment. They enable you to keep the common resources and logic of a project in a central repository and reuse it across different environments, different clusters.

Creating an environment file for a project means that users can create a template with variables that could be used to store environment-specific configuration.

For example, you might have a development, staging and production environment, each containing different clusters, databases, service URLs and authentication methods. Projects and environments allow you to write the logic and create the resources once, and use template placeholders for values that need to be replaced with the environment specific parameters.

To each project, you can create multiple environments, but only one can be active at a time for a project. Environments can be exported to files, and can be imported again to be used for another project, or on another cluster.

While environments are applied to a given project, they are not part of the project. They are not synchronized to Git when exporting or importing the project. This separation is what allows the storing of environment-specific values, or configurations that you do not want to expose to the Git repository.

  1. Navigate to the Streaming SQL Console.
    1. Navigate to Management Console > Environments, and select the environment where you have created your cluster.
    2. Select the Streaming Analytics cluster from the list of Data Hub clusters.
    3. Select Streaming SQL Console from the list of services.
      The Streaming SQL Console opens in a new window.
  2. Open a project from the Projects page of Streaming SQL Console.
    1. Select an already existing project from the list by clicking the Open button or Switch button.
    2. Create a new project by clicking the New Project button.
    3. Import a project by clicking the Import button.
    You are redirected to the Explorer view of the project.
  3. Click Environments from the Project Manager.
  4. Click New Environment.
  5. Provide a Name for the environment.
    Add keys and values as needed.
  6. After creating an environment file, you have the following options to manage it:
    1. Click Activate to apply the specified information for the project. To deactivate an active environment file, you need to click the Deactivate button.
    2. Click > Export to export the environment file.
    3. Click Import and search for an exported environment file on your computer to import an environment file.
    4. Click > Delete to remove the environment file from the project.
You can use a variable defined in your active environment in the following ways:
  • As values in the properties section of a CREATE TABLE statement as shown in the following example:
    CREATE TABLE (...) WITH ('key1'='${ssb.env.yourVariable}')
  • In the properties of a Kafka data source, for example bootstrap servers, truststore location
  • In the values of Catalog properties, for example Schema Registry URL, Kudu masters, Custom Catalog
To refer to an environment variable called yourVariable, you can use the following syntax: ${ssb.env.yourVariable}. You can use multiple substitutions or combine literals and variable substitutions in the same value string as shown in the following example:
'some-connector-url' = 'https://${ssb.env.connector-host}:${ssb.env.connector-port}'
Besides environments, it is also possible to define additional variables using the SET_VAR 'x' = 'y'; syntax in your queries. These do not become part of the environment and are not persisted, but live only in the current SQL session. They can be used for substitutions like environment variables, but without the ssb.env prefix as shown in the following example:
SET_VAR 'yourVariable' = 'someValue';
CREATE TABLE (...) WITH ('key1'='${yourVariable}')) 

You can reset a variable with the RESET_VAR 'x'; command.