[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Apache Airflow™](../index.md) > [Step-by-step guides](index.md) > Storing artifacts in Yandex Lockbox > Loading a variable from Yandex Lockbox

# Loading a variable from Yandex Lockbox

When working with Yandex Managed Service for Apache Airflow™, you can use [Yandex Lockbox](../../lockbox/index.md) to store artifacts that can be used in DAG files: connections, variables, and configuration data. Yandex Lockbox integrates into Managed Service for Apache Airflow™ via the [Yandex Lockbox Secret Backend](https://airflow.apache.org/docs/apache-airflow-providers-yandex/stable/secrets-backends/yandex-cloud-lockbox-secret-backend.html) provider. As a result, access to the secret storage is configured automatically.

You can load a variable from Yandex Lockbox using a [directed acyclic graph (DAG)](../concepts/index.md#about-the-service). Data for connecting to the DB is stored in Yandex Lockbox and automatically inserted into the graph.

## Getting started {#before-begin}

Issue the `lockbox.payloadViewer` [role](../../lockbox/security/index.md#lockbox-payloadViewer) to your service account.

{% note info %}

There is no need to assign the `lockbox.payloadViewer` role for the whole folder. It is enough to [assign it for a specific Yandex Lockbox secret](../../lockbox/operations/secret-access.md) once you [create it](#create-lockbox-secret).

{% endnote %}

## Create a Yandex Lockbox secret {#create-lockbox-secret}

For the Apache Airflow™ cluster to work correctly, your Yandex Lockbox secret's name must have this format: `airflow/<artifact_type>/<artifact_ID>`, where:
   * `<artifact_type>`: Decides what data will be stored in the secret. The allowed values are:
     * `connections`: Connections.
     * `variables`: Variables.
     * `config`: Configuration data.
   * `<artifact_ID>`: ID to use to access the artifact in Apache Airflow™.

[Create a Yandex Lockbox secret](../../lockbox/operations/secret-create.md) with the following parameters:
* **Name**: `airflow/variables/var_query`
* **Secret type**: `Custom`
* **Key**: `value`
* **Value**: `SELECT 2`

The `airflow/variables/var_query` secret will store the `value` variable with `SELECT 2` as its value.

## Prepare the DAG file and run the graph {#dag}

1. Create a local file named `load_variable_from_lockbox.py` and paste the following script to it:

   ```python
   from airflow.decorators import dag, task
   from airflow.models import Variable


   @dag(schedule=None)
   def load_variable_from_lockbox():
       @task
       def print_var_query():
           query = Variable.get_variable_from_secrets("var_query")
           print("query: ", query)
      
       print_var_query()


   load_variable_from_lockbox()
   ```

1. Upload the `load_variable_from_lockbox.py` DAG file to the bucket you created earlier. This will automatically create a graph with the same name in the Apache Airflow™ web interface.
1. [Open the Apache Airflow™ web interface](af-interfaces.md#web-gui).
1. Make sure a new graph named `load_variable_from_lockbox` has appeared in the **DAGs** section.

   It may take a few minutes to load a DAG file from the bucket.

1. To run the graph, click ![image](../../_assets/managed-airflow/trigger-dag.png =18x) in the line with its name.

## Check the result {#check-result}

To check the result in the Apache Airflow™ web interface:

{% list tabs group=instructions %}
   
- Apache Airflow™ version below 3.0 {#version-2}

  1. In the **DAGs** section, click the `load_variable_from_lockbox` graph.
  1. Go to the **Graph** section.
  1. Select **print_var_query**.
  1. Go to **Logs**.
  1. Make sure the logs contain the `query: SELECT 2` line. This means the query was successful.

- Apache Airflow™ version 3.0 or higher {#version-3}

  1. In the **DAGs** section, click the `load_variable_from_lockbox` graph.
  1. Go to **Tasks**.
  1. Select **print_var_query**.
  1. Go to **Tasks Instances**.
  1. Select the task instance.
  1. The **Logs** section will open.
  1. Make sure the logs contain the `query: SELECT 2` line. This means the query was successful.

{% endlist %}