Getting an IAM token
Written by
Updated at April 10, 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.py
and copy 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.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
get_iam_token
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
get_iam_token
graph. - Go to the Graph section.
- Select the print_iam_token job.
- Go to Logs.
- Make sure the logs contain the
"token: ", iam_token
string. This means the query was successful.