Environment

Sling looks for connection credentials in several places:

One of the easiest ways is to manage your connections is to use the sling conns sub-command. Follow in the next section.

Managing Connections

Sling makes it easy to set, list and test connections. You can even see the available streams in a connection by using the discover sub-command.

$ sling conns -h
conns - Manage and interact with local connections

See more details at https://docs.slingdata.io/sling-cli/

  Usage:
    conns [discover|list|set|test]

  Subcommands:
    discover   list available streams in connection
    list       list local connections detected
    test       test a local connection
    unset      remove a connection from the sling env file
    set        set a connection in the sling env file
    exec       execute a SQL query on a Database connection

  Flags:
       --version   Displays the program version string.
    -h --help      Displays help with available flag, subcommand, and positional value parameters.

Set Connections

Here we can easily set a connection with the sling conns set command and later refer to them by their name. This ensures credentials are not visible by other users when using process monitors, for example.

To see what credential keys are necessary/accepted for each type of connector, click below:

  • File/Storage Connections (see here)

  • Database Connections (see here)

List Connections

Once connections are set, we can run the sling conns list command to list our detected connections:

Test Connections

We can also test a connection by running the sling conns test command:

Discover Connections

We can easily discover streams available in a connection with the sling conns discover command:

Show column level information:

Credentials Location

Sling Env File (env.yaml)

The Sling Env file is the primary way sling reads connections globally. It needs to be saved in the path ~/.sling/env.yaml where the ~ denotes the path of the user Home folder, which can have different locations depending on the operating system (see here for Windowsarrow-up-right, here for Macarrow-up-right and here for Linuxarrow-up-right). Sling automatically creates the .sling folder in the user home directory, which is typically as shown below:

  • Linux: /home/<username>/.sling, or /root/.sling if user is root

  • Mac: /Users/<username>/.sling

  • Windows: C:\Users\<username>\.sling

Once in the user home directory, setting the Sling Env File (named env.yaml) is easy, and adheres to the structure below. Running sling the first time will auto-create it. You can alternatively provide the environment variable SLING_HOME_DIR.

To see what credential keys are necessary/accepted for each type of connector, click below:

  • File/Storage Connections (see here)

  • Database Connections (see here)

Dot-Env File (.env.sling)

Sling automatically loads a .env.sling file from the current working directory when it starts. This lets you define per-project connections and variables without modifying the global env.yaml. This applies to version 1.5.10+.

This is useful when you have multiple projects, each with their own connections or credentials. Simply place a .env.sling file in the project directory, and Sling will pick it up automatically when run from that directory.

The file uses a simple KEY=VALUE format (one per line). Comments and blank lines are supported. Values can optionally be wrapped in single or double quotes.

circle-info

Existing environment variables are not overwritten. If a variable is already set in the shell environment, the value from .env.sling will be ignored. This means shell-level overrides always take precedence.

circle-exclamation

Environment Variables

Sling also reads environment variables. Simply export a connection URL (or YAML payload) to the current shell environment to use them.

To see examples of setting environment variables for each type of connector, click below:

  • File/Storage Connections (see here)

  • Database Connections (see here)

DBT Profiles (~/dbt/profiles.yml)

Sling also reads dbt profiles connections! If you're already set up with dbt cli locally, you don't need to create additional duplicate connections.

See herearrow-up-right for more details.

Location String

The location string is a way to describe where sling should look for a file object or database object. It is used in a few places, such as the SLING_STATE env var, as well as Hooks such as delete, copy and inspect.

The proper input format is CONN_NAME/path/to/key for storage connections, or CONN_NAME/[database.]schema.table for database objects.

Local location examples:

  • local/relative/path

  • local/../parent/relative/path

  • local//absolute/linux/path

  • local/C:/absolute/windows/path

For cloud or remote storage connections (with defined AWS_S3, GCP, AZURE, SFTP connections):

  • aws_s3/path/to/folder

  • gcp/path/to/folder/file.parquet

  • azure/path/to/folder/file.log

  • sftp/relative/path/to/folder/file.log

  • sftp//absolute/path/to/folder/file.log

Database location examples (for hooks like inspect):

  • postgres/public.users - PostgreSQL table in public schema

  • mysql_db/analytics.events - MySQL table in analytics schema

  • snowflake/DATABASE.SCHEMA.TABLE - Snowflake table with explicit database

  • bigquery/project.dataset.table_name - BigQuery table

  • oracle_db/HR.EMPLOYEES - Oracle table in HR schema

  • mssql/dbo.customers - SQL Server table in dbo schema

circle-exclamation

Last updated

Was this helpful?