Getting an IAM token
Written by
Updated at October 23, 2025
Using a directed acyclic graph (DAG), you can get the IAM token of the service account attached to an Apache Airflow™ cluster.
Prepare the DAG file and run the graph
-
Create a local file named
get_iam_token.pyand paste the following script to it:from airflow.decorators import dag, task import yandexcloud @dag(schedule=None) def get_iam_token(): @task def print_iam_token(): sdk = yandexcloud.SDK() token = sdk._channels._token_requester.get_token() print("token: ", token[:20]) print_iam_token() get_iam_token() -
Upload the
get_iam_token.pyDAG 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
get_iam_tokenhas appeared in the DAGs section.It may take a few minutes to load 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:
Apache Airflow™ version below 3.0
Apache Airflow™ version 3.0 or higher
- In the DAGs section, click
get_iam_token. - Go to the Graph section.
- Select print_iam_token.
- Go to Logs.
- Make sure the logs contain the
"token: " <iam_token_value>line. This means the query was successful.
- In the DAGs section, click
get_iam_token. - Go to Tasks.
- Select print_iam_token.
- Go to Tasks Instances.
- Select the task instance.
- The Logs section will open.
- Make sure the logs contain the
"token: " <iam_token_value>line. This means the query was successful.