<?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 NaeemAkhtar on Medium]]></title>
        <description><![CDATA[Stories by NaeemAkhtar on Medium]]></description>
        <link>https://medium.com/@nakhtar.etc?source=rss-b2d79ab7166d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*pOql9eDEFZMVQGRLAWII7w.jpeg</url>
            <title>Stories by NaeemAkhtar on Medium</title>
            <link>https://medium.com/@nakhtar.etc?source=rss-b2d79ab7166d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 07:47:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nakhtar.etc/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[Fetch Databricks details]]></title>
            <link>https://medium.com/@nakhtar.etc/fetch-databricks-details-06978a82a390?source=rss-b2d79ab7166d------2</link>
            <guid isPermaLink="false">https://medium.com/p/06978a82a390</guid>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[azure-administrator]]></category>
            <category><![CDATA[powershell-script]]></category>
            <dc:creator><![CDATA[NaeemAkhtar]]></dc:creator>
            <pubDate>Mon, 10 Feb 2025 15:19:30 GMT</pubDate>
            <atom:updated>2025-02-10T15:19:30.488Z</atom:updated>
            <content:encoded><![CDATA[<p>As a platform engineer or infrastructure cloud engineer or databricks administrator it is very crucial to gather detailed insights into their network configurations.</p><p>Blog created the fetch the azure databricks details including virtual network, subnets and security groups attached if any with databricks subject considering vnet injected databricks workspaces when we can fetch the details depends of customize subscription.</p><p>Wrote the PowerShell script to fetch the details with configurable subscriptions as a wildcard entry example if anybody looking for only “DEV” or “PROD” details and subscription name has those prefixes in it.</p><h3><strong>Prerequisites:</strong></h3><p>Before executing the PowerShell script, ensure you have the following:</p><ol><li>Azure PowerShell module installed.</li><li>Service Principal details that has a proper RBAC permission to fetch the data across the subscription and network details.</li></ol><p><strong><em>Note:</em></strong><em> No Owner or Contributor RBAC required, Reader at management level will be sufficient.</em></p><p>3. SPN authentication setup for secure execution.</p><p>To authenticate via SPN “Service Principal” use below code.</p><p>This piece of code help to authenticate with azure portal using SPN.</p><pre>$tenantId = &quot;&lt;Your_Tenant_ID&gt;&quot;<br>$appId = &quot;&lt;Your_App_ID&gt;&quot;<br>$secret = ConvertTo-SecureString &quot;&lt;Your_Client_Secret&gt;&quot; -AsPlainText -Force<br>$credential = New-Object System.Management.Automation.PSCredential($appId, $secret)<br>Connect-AzAccount -ServicePrincipal -Credential $credential -TenantId $tenantId</pre><p><strong>Below script perform following steps:</strong></p><ol><li>Retrieves all Azure Subscriptions available for SPN.</li><li>Iterates through each subs and fetch the databricks workspaces.</li><li>Extract relevant details such as: (Name, RG, Subs, Location etc.)</li><li>Fetches associated virtual network and subnets with databricks and security group attached with databricks subnets.</li><li>Writes the collected information to CSV file.</li></ol><h3><strong>Script:</strong></h3><pre>$output = &quot;&lt;Path&gt;&quot;<br>$subscriptionFilter = &quot;*wildcard*&quot;  # Modify this wildcard pattern as needed<br>$subs = Get-AzSubscription | Where-Object { $_.Name -like $subscriptionFilter }<br><br>&quot;DBK_Name, URL, Subs, RG, Location, Vnet, Vnet_RG, Public_Subnet, Private_Subnet, Subnet_NSG, NSG_RG&quot; | Out-File -FilePath $output<br><br>foreach ($sub in $subs) {<br>    Select-AzSubscription -SubscriptionId $sub.Id<br>    $dbks = Get-AzDatabricksWorkspace<br>    $vnets = Get-AzVirtualNetwork | Group-Object -Property Name -AsHashTable -AsString<br><br>    foreach ($dbk in $dbks) {<br>        $dbk_vnet_name = ($dbk.CustomVirtualNetworkIdValue -split &quot;/&quot;)[-1]<br>        $dbk_pub_sub = $dbk.CustomPublicSubnetNameValue<br>        $dbk_pri_sub = $dbk.CustomPrivateSubnetNameValue<br>        <br>        if ($vnets[$dbk_vnet_name]) {<br>            $vnet = $vnets[$dbk_vnet_name]<br>            $subnet = $vnet.Subnets | Where-Object { $_.Name -eq $dbk_pub_sub }<br>            <br>            if ($subnet -and $subnet.NetworkSecurityGroup) {<br>                $nsg = Get-AzResource -ResourceId $subnet.NetworkSecurityGroup.Id<br>                &quot;$($dbk.Name), $($dbk.Url), $($sub.Name), $($dbk.ResourceGroupName), $($dbk.Location), $dbk_vnet_name, $($vnet.ResourceGroupName), $dbk_pub_sub, $dbk_pri_sub, $($nsg.Name), $($nsg.ResourceGroupName)&quot; | Out-File -FilePath $output -Append<br>            }<br>        }<br>    }<br>}</pre><h3><strong>Conclusion:</strong></h3><p>This PowerShell script provide comprehensive view of Azure Databricks workspaces and their network configuration across multiple subs.</p><p><strong><em>Note</em></strong><em>: SPN should have permission on all the available subsections.</em></p><h3><strong>Next Step:</strong></h3><ol><li>Schedule this script to run periodically using azure automation or cron job.</li><li>Extend the Script to include more network properties like NSG rules, route tables and other information.</li><li>Integrate the output with other tools for better visualization of monitoring.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=06978a82a390" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mount ADLS on Databricks]]></title>
            <link>https://medium.com/@nakhtar.etc/mount-adls-on-databricks-fe3b54da07be?source=rss-b2d79ab7166d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe3b54da07be</guid>
            <category><![CDATA[databricks]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[adls-gen2]]></category>
            <category><![CDATA[databricks-delta-lake]]></category>
            <dc:creator><![CDATA[NaeemAkhtar]]></dc:creator>
            <pubDate>Sun, 25 Feb 2024 09:44:18 GMT</pubDate>
            <atom:updated>2024-02-25T09:44:18.926Z</atom:updated>
            <content:encoded><![CDATA[<p>Azure Data Lake Storage Gen2 (ADLS Gen2) and Databricks stand as robust pillars in the Microsoft Azure ecosystem. The synergy achieved by mounting ADLS Gen2 on Databricks unlocks a plethora of opportunities for streamlined data processing and analytics. This article guides you through the step-by-step process of integrating ADLS Gen2 with Databricks, delving into the benefits and considerations that come with this powerful collaboration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RNJuxR4ppgX_lZnlKfnnhQ.png" /></figure><h3>Let’s Mount ADLS Gen2 on Databricks:</h3><h3>Step 1: Set Up Infrastructure.</h3><p>Create and databricks workspace and cluster attach a notebook with cluster if infra is not ready else create a new notebook and attach it with existing cluster from databricks workspace.</p><h3>Step 2: Configure Storage Key and Endpoint</h3><p>Retrieve the storage account key, SAS for authentication and endpoint for your ADLS Gen2 account. Configure these details in the Databricks workspace, which will be used to establish a connection.</p><h3>Step 3: Mount ADLS Gen2 on Databricks</h3><p>Use the Databricks notebook to run commands that mount the ADLS Gen2 storage. Specify the storage account, container, mount point, and the access key.</p><p>The provided code snippet utilizes Databricks’ dbutils.fs.mount function to mount Azure Data Lake Storage Gen2 (ADLS Gen2) onto a specified mount point within the Databricks environment. Let&#39;s break down the components of this command:</p><pre># Example mount command <br>dbutils.fs.mount( source = &quot;abfss://&lt;container_name&gt;@&lt;storage_account_name&gt;.dfs.core.windows.net/&quot;, mount_point = &quot;/mnt/&lt;mount_point&gt;&quot;, extra_configs = {&quot;&lt;conf-key&gt;&quot;:dbutils.secrets.get(scope = &quot;&lt;scope-name&gt;&quot;, key = &quot;&lt;key-name&gt;&quot;)})</pre><ul><li>source: Specifies the source location to be mounted. In this case, it uses the Azure Blob File System (abfss) protocol to connect to the specified ADLS Gen2 container. Replace &lt;container_name&gt; and &lt;storage_account_name&gt; with the actual names of your ADLS Gen2 container and storage account, respectively.</li><li>mount_point: Defines the mount point within the Databricks environment where the ADLS Gen2 will be accessible. Replace &lt;mount_point&gt; with the desired path for mounting.</li><li>extra_configs: Allows you to provide additional configurations. In this example, it includes a configuration key (denoted as &lt;conf-key&gt;) with a corresponding value retrieved from Databricks secrets. This is useful for securely handling sensitive information such as keys or credentials.</li><li>dbutils.secrets.get: Fetches the secret associated with the specified scope (&lt;scope-name&gt;) and key (&lt;key-name&gt;). This is a secure way to manage and access sensitive information within Databricks.</li><li>in the above snippet we used azure key vault service to protect out credentials in it.</li></ul><p><strong>Databricks secrets Scope: </strong>there are 2 types of databricks secrets scope.</p><p>1. Azure Key Vault-backed Secret Scope: Used as above.</p><p>2. Databricks-backed Secret Scope: will explain in later post.</p><p>By executing this code, you establish a connection between Databricks and ADLS Gen2, enabling seamless data access and processing within the Databricks environment. This mount operation essentially links the specified ADLS Gen2 container to the specified mount point, allowing users to interact with the data as if it were part of the local file system.</p><p>NOTE: Given that ADLS Gen2 resides on the public network, there is no requirement for a separate network establishment.</p><p>But if ADLS on Selected network in that case we need to make sure network connectivity must be enabled from databricks to ADLS Gen2 either through Private Endpoint or via Service End Point.</p><p>Will cover Databricks to ADLS Gen2 via Selected network in my next Post.</p><h3>Pros of Mounting ADLS Gen2 on Databricks</h3><h3>1. Unified Data Management:</h3><ul><li>Efficient Data Access: Mounting ADLS Gen2 allows Databricks to directly access data in its native storage, avoiding unnecessary data transfers.</li></ul><h3>2. Scalability and Performance:</h3><ul><li>Parallel Processing: Databricks can leverage the distributed architecture of ADLS Gen2 for parallel processing, enhancing scalability and performance.</li></ul><h3>3. Unified Analytics:</h3><ul><li>Seamless Integration: Analysts and data scientists can seamlessly integrate ADLS Gen2 data into their analytics workflows without the need for extensive data movement.</li></ul><h3>4. Consistency Across Environments:</h3><ul><li>Development to Production: Mounting facilitates consistency from development to production, streamlining the deployment of data pipelines.</li></ul><h3>Cons of Mounting ADLS Gen2 on Databricks</h3><h3>1. Security:</h3><ul><li>As mounting of storage at workspace level and couldn’t control the access and permissions on mount point.</li><li>If we use access key to mount that has full access on ADLS and all user who are accessing it will get full access on ADLS.</li><li>Not advisable in case of shared storage.</li></ul><p>How to Over cum Security issue:</p><ul><li>Use Spark Configuration of databricks cluster to integrate with ADLS2.</li><li>Use Service Principal to authenticate with ADLS2. with limited access:</li></ul><pre>spark.hadoop.fs.azure.account.auth.type.&lt;storage-account&gt;.dfs.core.windows.net OAuth<br>spark.hadoop.fs.azure.account.oauth.provider.type.&lt;storage-account&gt;.dfs.core.windows.net org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider<br>spark.hadoop.fs.azure.account.oauth2.client.id.&lt;storage-account&gt;.dfs.core.windows.net &lt;application-id&gt;<br>spark.hadoop.fs.azure.account.oauth2.client.secret.&lt;storage-account&gt;.dfs.core.windows.net {{secrets/&lt;secret-scope&gt;/&lt;service-credential-key&gt;}}<br>spark.hadoop.fs.azure.account.oauth2.client.endpoint.&lt;storage-account&gt;.dfs.core.windows.net https://login.microsoftonline.com/&lt;directory-id&gt;/oauth2/token</pre><ul><li>Another option to use notebook authentication for ADLS2:</li></ul><pre>service_credential = dbutils.secrets.get(scope=&quot;&lt;secret-scope&gt;&quot;,key=&quot;&lt;service-credential-key&gt;&quot;)</pre><pre>spark.conf.set(&quot;fs.azure.account.auth.type.&lt;storage-account&gt;.dfs.core.windows.net&quot;, &quot;OAuth&quot;)<br>spark.conf.set(&quot;fs.azure.account.oauth.provider.type.&lt;storage-account&gt;.dfs.core.windows.net&quot;, &quot;org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider&quot;)<br>spark.conf.set(&quot;fs.azure.account.oauth2.client.id.&lt;storage-account&gt;.dfs.core.windows.net&quot;, &quot;&lt;application-id&gt;&quot;)<br>spark.conf.set(&quot;fs.azure.account.oauth2.client.secret.&lt;storage-account&gt;.dfs.core.windows.net&quot;, service_credential)<br>spark.conf.set(&quot;fs.azure.account.oauth2.client.endpoint.&lt;storage-account&gt;.dfs.core.windows.net&quot;, &quot;https://login.microsoftonline.com/&lt;directory-id&gt;/oauth2/token&quot;)</pre><blockquote>dbutils.fs.unmount(mount_point)</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe3b54da07be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Databricks REST API]]></title>
            <link>https://medium.com/@nakhtar.etc/databricks-rest-api-f8c96eef4a7c?source=rss-b2d79ab7166d------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8c96eef4a7c</guid>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[rest-api]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[databricks]]></category>
            <dc:creator><![CDATA[NaeemAkhtar]]></dc:creator>
            <pubDate>Sat, 10 Feb 2024 13:40:49 GMT</pubDate>
            <atom:updated>2024-02-10T13:40:49.331Z</atom:updated>
            <content:encoded><![CDATA[<p>Databricks, the cloud-based big data analytics and ML platform, permits users to connect with Apache Spark. While the Databricks workspace provides a user-friendly interface, the REST API helps a world of possibilities for automation, integration, and custom workflows. In this section, I will focus on Databricks REST API, shedding light on its capabilities and how it can be leveraged the REST API features.</p><p><strong>Understanding the Databricks REST API</strong></p><p>The Databricks REST API exposes a set of HTTP endpoints that allow users to interact programmatically with their Databricks workspace. This API covers a wide range of functionalities, enabling users to manage clusters, notebooks, libraries, jobs, and more.</p><p><strong>Authentication and Authorization</strong></p><p>Before diving into the API, it’s crucial to understand the authentication and authorization mechanisms. The Databricks REST API uses personal access tokens PAT for authentication. Users can generate these tokens in the Databricks workspace, ensuring secure and controlled access.</p><p><strong>Key API Endpoints</strong></p><p><strong>Clusters API:</strong></p><p>Create a cluster:</p><blockquote>POST /api/2.0/clusters/create</blockquote><p>List clusters:</p><blockquote>GET /api/2.0/clusters/list</blockquote><pre>Ex: curl --request GET &quot;https://${DATABRICKS_HOST}/api/2.0/clusters/get&quot; \<br> — header “Authorization: Bearer ${DATABRICKS_TOKEN}” \<br> — data ‘{ “cluster_id”: “1234–567890-a12bcde3” }’</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a6TDDEM1LqNjSqBsJe7TeA.png" /></figure><p><strong>Notebooks API:</strong></p><p>Import a notebook:</p><blockquote>POST /api/2.0/workspace/import</blockquote><p>Export a notebook:</p><blockquote>GET /api/2.0/workspace/export</blockquote><p><strong>Libraries API:</strong></p><p>Install a library:</p><blockquote>POST /api/2.0/libraries/install</blockquote><p><strong>List installed libraries:</strong></p><blockquote>GET /api/2.0/libraries/list</blockquote><p><strong>Jobs API:</strong></p><p>Submit a job:</p><blockquote>POST /api/2.0/jobs/runs/submit</blockquote><p><strong>List jobs:</strong></p><blockquote>GET /api/2.0/jobs/runs/list</blockquote><p><strong>Sample code: Cluster Creation via API</strong></p><p>A simple example of using the Databricks REST API to automate the creation of a cluster. We’ll use the clusters/create endpoint.</p><pre>curl -X POST -H “Authorization: Bearer &lt;DATABRICKS_TOKEN&gt;” -H “Content-Type: application/json” \ <br>— data @- “https://&lt;DATABRICKS_WORKSPACE_URL&gt;/api/2.0/clusters/create” &lt;&lt;EOF <br>{ <br>  “cluster_name”: “admin-cluster”, <br>  “spark_version”: “13.3.x-scala2.12”,<br>  “node_type_id”: “Standard_DS3_v2”,<br>  “num_workers”: 2,  <br>  “autoscale”: {<br>      “min_workers”: 2,<br>      “max_workers”: 10<br>     }<br>}<br>EOF</pre><p>Replace &lt;DATABRICKS_TOKEN&gt; with your personal access token and &lt;DATABRICKS_WORKSPACE_URL&gt; with the actual URL of your Databricks workspace.</p><h4><strong>.netrc file</strong></h4><p>Its not a good practice to pass the PAT credential in code for security concern to avoid this we can store PAT with databricks workspace URL in config file called .netrc</p><p>So we no need to pass the authentication header in API call.</p><pre>machine northeurope.azuredatabricks.net login token password dapicxxxxxxxxxxxxxxxxxxxxx</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8c96eef4a7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Databricks CLI]]></title>
            <link>https://medium.com/@nakhtar.etc/databricks-cli-253f552b730a?source=rss-b2d79ab7166d------2</link>
            <guid isPermaLink="false">https://medium.com/p/253f552b730a</guid>
            <category><![CDATA[databricks-basics]]></category>
            <category><![CDATA[cli]]></category>
            <category><![CDATA[databricks]]></category>
            <dc:creator><![CDATA[NaeemAkhtar]]></dc:creator>
            <pubDate>Sun, 04 Feb 2024 13:04:01 GMT</pubDate>
            <atom:updated>2024-02-04T13:04:01.552Z</atom:updated>
            <content:encoded><![CDATA[<p>Databricks Command-Line Interface (CLI) is a command-line tool provided by Databricks to interact with Databricks workspaces and perform various operations from the command line. The Databricks CLI can be useful for several reasons:</p><ol><li><strong>Scripting and Automation:</strong> The CLI allows you to automate various tasks and workflows by scripting commands. This is especially useful for automating repetitive tasks, deploying jobs, or managing clusters programmatically.</li><li><strong>Integration with Other Tools:</strong> The CLI can be integrated into scripts or used in conjunction with other tools and platforms, making it easier to incorporate Databricks into existing workflows or toolchains.</li><li><strong>Batch Operations:</strong> If you need to perform operations on Databricks clusters, libraries, jobs, or notebooks in a batch mode, the CLI provides a convenient way to do this without manually interacting with the Databricks workspace UI.</li><li><strong>CI/CD Pipelines:</strong> For continuous integration and continuous delivery (CI/CD) pipelines, the Databricks CLI can be used to deploy notebooks, manage clusters, and execute jobs programmatically.</li><li><strong>Remote Execution:</strong> The CLI allows you to execute commands remotely, making it convenient for administrators or developers who prefer command-line interfaces over graphical user interfaces (GUIs).</li><li><strong>Version Control Integration:</strong> You can use the CLI to manage notebooks and other artifacts in a version control system, allowing for better collaboration and version tracking.</li><li><strong>User and Group Management:</strong> As is very boring and time taking to add user and create groups on databricks workspace and specially when we have a bulk user, DBK CLI make it very easy IAM management.</li></ol><p>Here are some common use cases for the Databricks CLI:</p><ul><li>Creating and managing clusters.</li><li>Importing and exporting notebooks.</li><li>Installing and managing libraries.</li><li>Submitting and managing jobs.</li><li>Running and scheduling tasks.</li></ul><p>To use the Databricks CLI, you need to install it on your local machine, and you’ll typically authenticate using a token generated from the Databricks workspace. The CLI commands are executed in a terminal or command prompt.</p><p>Remember that the Databricks CLI is just one of the ways to interact with Databricks, and depending on your preferences and requirements, you might also use the Databricks REST API, Databricks notebooks, or other Databricks integrations.</p><p><strong>How to Configuration Profiles for the Databricks CLI</strong></p><ol><li><strong>Multiple Profiles</strong>: The configure command group enables you to authenticate the Databricks CLI with Databricks using personal access tokens. You can create multiple configuration profiles, each containing authentication information such as the Databricks workspace URL and an access token. Profiles have programmatic names like DEFAULT, DEV, or PROD.</li><li><strong>Creating a Configuration Profile</strong>: To create a configuration profile, run the following command:</li></ol><blockquote>&gt; databricks configure — host &lt;workspace-url&gt;</blockquote><p>Replace &lt;workspace-url&gt; with your instance name.</p><ol><li>The command prompts you to enter your Databricks personal access token associated with the specified workspace URL.</li><li>After entering your access token, it’s stored in the ~/.databrickscfg file on Linux or macOS, or %USERPROFILE%\\.databrickscfg on Windows.</li><li>The file contains a default connection profile named DEFAULT:</li></ol><blockquote>[DEFAULT]</blockquote><blockquote>&gt;host = &lt;workspace-url&gt;</blockquote><blockquote>&gt;token = &lt;access-token&gt;</blockquote><ol><li>You can use a different name for your connection profile by adding the — profile option to the configure command:</li></ol><blockquote>databricks configure — host &lt;workspace-url&gt;- - profile &lt;profile-name&gt;</blockquote><p>Tip: Press Tab after — profile or -p to display existing configuration profiles to choose from.</p><ol><li>Multiple Profiles for Versatility: Adding multiple connection profiles to the .databrickscfg file allows you to swiftly run commands across various workspaces. Specify the target profile’s name using the — profile option in commands.#databrickcli #cli #databricks</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=253f552b730a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>