[Yandex Cloud documentation](../../index.md) > [Yandex Managed Service for Apache Airflow™](../index.md) > [Step-by-step guides](index.md) > Working with DAG files > Getting an IAM token

# Getting an IAM token

Using a [directed acyclic graph (DAG)](../concepts/index.md#about-the-service), you can get the [IAM token](../../iam/concepts/authorization/iam-token.md) of the service account attached to an Apache Airflow™ cluster.

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

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

   ```python
   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()
   ```

1. 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.
1. [Open the Apache Airflow™ web interface](af-interfaces.md#web-gui).
1. Make sure a new graph named `get_iam_token` 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 lower than 3.0 {#version-2}

  1. In the **DAGs** section, click the `get_iam_token` graph.
  1. Go to the **Graph** section.
  1. Select **print_iam_token**.
  1. Go to **Logs**.
  1. Make sure the logs contain the `"token: " <iam_token_value>` line. This means the query was successful.

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

  1. In the **DAGs** section, click the `get_iam_token` graph.
  1. Go to **Tasks**.
  1. Select **print_iam_token**.
  1. Go to **Tasks Instances**.
  1. Select the task instance.
  1. The **Logs** section will open.
  1. Make sure the logs contain the `"token: " <iam_token_value>` line. This means the query was successful.

{% endlist %}