<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ramachaitanya on Medium]]></title>
        <description><![CDATA[Stories by Ramachaitanya on Medium]]></description>
        <link>https://medium.com/@ramachaitanya0?source=rss-e56b171c5786------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Ramachaitanya on Medium</title>
            <link>https://medium.com/@ramachaitanya0?source=rss-e56b171c5786------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 12:32:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ramachaitanya0/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Automation of Databricks Access Token Creation.]]></title>
            <link>https://medium.com/@ramachaitanya0/automation-of-databricks-access-token-creation-ea3c2894baf6?source=rss-e56b171c5786------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea3c2894baf6</guid>
            <category><![CDATA[azure-data-factory]]></category>
            <category><![CDATA[etl-pipeline]]></category>
            <category><![CDATA[azure-databricks]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[data-engineer]]></category>
            <dc:creator><![CDATA[Ramachaitanya]]></dc:creator>
            <pubDate>Wed, 13 Apr 2022 05:06:16 GMT</pubDate>
            <atom:updated>2022-04-13T06:35:26.763Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Introduction</strong></h3><p>If you are a Data Engineer , you must be using an ETL Tool for running and monitoring all your pipelines. If you are using Azure Data Factory(ADF) and Databricks to run and monitor all your pipelines, you might have faced Databricks access token expiry problem. This might cause failure of all the pipelines.</p><p>To schedule the Databricks notebooks in ADF, ADF uses Databricks linked services to access the Databricks workspace and cluster. To setup a Databricks <a href="https://docs.microsoft.com/en-us/azure/data-factory/concepts-linked-services">Linked Service</a>, we need to provide a Databricks access token to the Linked Service.You can provide the access token value directly or you can give azure key vault secret name which stores your Databricks Access Token.</p><p>The Databricks Access Token comes with an expiry date, If we hadn’t created a new access token and replaced the old access token with new access token in the Databricks Linked Service before it expires, all the notebooks using this linked service would eventually fail. There is no alerting mechanism to send alerts about the expiry of the access tokens. You have to remember the expiry date of access token and manually create a new access token, add the new access token in Linked Service. If you miss or forgot to create a new access token before the last access token expires, all the pipelines would fail.</p><h3>Solution :</h3><p>In this article, I will be creating a Databricks Notebook which automatically creates a new access token before the last access token expires and stores the new access token value in an Azure key Vault Secret. You can provide this Azure key Vault Secret to Databricks Linked Service and you don’t have to worry about the access tokens ever.</p><p><strong>Prerequisites : </strong>To implement this solution, we need the below Azure resources and Azure SDK’s</p><ol><li>Azure Key Vault Secret</li><li>azure key vault secrets SDK</li><li>azure-identity SDK</li><li>Azure Tenant ID , Azure Client ID and Azure Client Secret ( Administrator provides these details)</li><li>Secret Scope</li><li>Databricks Access Token</li></ol><p>Azure key vault is useful to store the secrets and our Databricks access token can be stored as a Secret and can access it through Key Vault Api’s. If you are not aware of the Azure key vault Service, you can read about it <a href="https://docs.microsoft.com/en-in/azure/key-vault/general/overview">here</a>. You need to install azure key vault secrets and azure identity SDK’s using pip. Secret Scope is a way to access the Azure Key Vault Secret directly from the Databricks. You can create a Secret Scope in your Databricks workspace following these <a href="https://docs.microsoft.com/en-us/azure/databricks/security/secrets/secret-scopes#akv-ss">instructions</a>. Create a Secret Scope or find if any Secret Scope is created for your Databricks Workspace and save the secret scope name. Now, Let’s go to the coding part. To create Databricks Access token , refer to this <a href="https://docs.databricks.com/dev-tools/api/latest/authentication.html">documentation</a>.</p><h3><strong>Steps :</strong></h3><p><strong>Step 1:</strong> Create a Secret in Azure key vault, create Databricks Access token and store the access token in the secret. Save the Secret name and the URI (DNS name) of the Azure key Vault. We will provide this secret name to Databricks linked service, so that the linked service takes the access token value from Azure Key Vault. To create a Secret in Azure Key Vault , refer to this <a href="https://docs.microsoft.com/en-us/azure/key-vault/general/quick-create-portal">documentation</a>.</p><p><strong>Step 2 :</strong> Install the required libraries using the below code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7aeecb8423624f0a0c1efaa7c79b9efd/href">https://medium.com/media/7aeecb8423624f0a0c1efaa7c79b9efd/href</a></iframe><p>Define environment Variables for Authentication in a Databricks Notebook. Azure client id , tenant id and client secret are needed to access the Azure key Vault.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/21667cdbb61d04c8c79a0d1d0fab7e1d/href">https://medium.com/media/21667cdbb61d04c8c79a0d1d0fab7e1d/href</a></iframe><p><strong>Step 3 </strong>: Accessing the Azure Key Vault and its Secrets to get the expiry date of current Databricks access token . You can get the URI(DNS name) of Azure key Vault from its properties . Calculate the number of days, the access token is going to expire from today.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7fa1aa9d865de33a40cd2c2553052c1d/href">https://medium.com/media/7fa1aa9d865de33a40cd2c2553052c1d/href</a></iframe><p>Step 4 : In this step, we will check the expiry date of secret and you can mention the number of days before the expiry date to change the access token. if the date difference between today and expiry date is less than the mentioned days, the code will create a new access token through a POST Request and stores it in the azure key vault secret. You can also set the lifetime of the new access token.If the post request wasn’t successful, then we manually stop the notebook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cde67c4e13e093a8fe6367e196d09163/href">https://medium.com/media/cde67c4e13e093a8fe6367e196d09163/href</a></iframe><p>Step 5 : We can schedule this notebook in ADF and run at required frequency. After that, you would never to worry about the access token expiry problem.</p><p>Thanks for reading , I hope you found my article useful. please share similar hacks you use in your day to day work.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea3c2894baf6" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>