Reading a file from Yandex Object Storage
Written by
Updated at April 10, 2025
Use a directed acyclic graph (DAG) to read files from Yandex Object Storage of the service account linked to an Apache Airflow™ cluster.
Prepare the DAG file and run the graph
-
Create a local file named
read_file_from_dags_bucket.py
and copy the following script to it:from airflow.settings import DAGS_FOLDER from airflow.decorators import dag, task @dag(schedule=None) def read_file_from_dags_bucket(): @task def read_file(): with open(f'{DAGS_FOLDER}/data/airflow.txt') as file: content = file.read() print(f"file content: {content}") read_file() read_file_from_dags_bucket()
-
Upload the
read_file_from_dags_bucket.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. -
Make sure a new graph named
read_file_from_dags_bucket
has appeared in the DAGs section.It may take a few minutes to upload a DAG file from the bucket.
-
To run the graph, click
in the line with its name.
Check the result
To check the result in the Apache Airflow™ web interface:
- In the DAGs section, open the
read_file_from_dags_bucket
graph. - Go to the Graph section.
- Select the read_file job.
- Go to Logs.
- Make sure the logs contain the
file content: {content}
string, wherecontent
is the file content. This means the query was successful.