Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

ibarrau

[Azure] Pause Resume Fabric, Embedded or AAS with SimplePBI

Prerequisites

1. The first thing you need are two prerequisites:

 

pip install simplepbi --upgrade

 

2. An App registered in Azure with a secret created to use as a Service Principal. Copy the Tenant ID, Client or App ID, and the generated Secret.

Execution
To begin, go to your Azure resource (Fabric, PBI Embedded, or AAS) and grant permission in the Access control (IAM) to the Service Principal (Registered App) as "Contributor". This permission will allow it to execute actions like start and stop. From that point on, we are free to execute the simple code.

 

from simplepbi import azpause

# Initialize the object authenticating Azure
azure = azpause.Azpause(TENANT_ID, client_id, client_secret)

# Run methods of the object for pause or resume
azure.resume_resource(subscriptionId, resourceGroupName, resourceType, resourceName)
azure.pause_resource(subscriptionId, resourceGroupName, resourceType, resourceName)

 

Just that simple with three lines: import the library, authenticate by creating an object, and call the object's method specifying values that can be copied from the resource "Overview":

  • subscriptionId: Subscription ID, not the tenant ID.
  • resourceGroupName: Name of the resource group where the resource was created.
  • resourceType: Type of resource, one of "FABRIC", "PBI", or "AAS".
  • resourceName: Name of the AAS server or the Fabric/Embedded capacity.

Link to repo with documentation: GitHub - SimplePBI

Automating in Azure

One of the best uses for this action is scheduling the execution of these lines during known times when the resources are not in use. This can be done locally using Windows Schedule or in Azure to avoid dependency on a VM. Within Azure, there are various services; for example, Azure Functions could be used. I will demonstrate with an Automation account creating a Runbook.

In the Azure portal, create an Automation account. The code we will use will be in Python 3.8. Once the account is created, navigate to Python Packages and add the library:

ibarrau_0-1719347316278.png

To add the library, download the Wheel file from SimplePBI: SimplePBI on PyPI.

After downloading, select "Add a Python Package" using the + sign. Once added, the "whl" file should be recognized, and you should select Python version 3.8.

ibarrau_1-1719347408121.png

This setup allows us to import SimplePBI into the code of our runbook. After loading the library, which may take several minutes, create a runbook from the menu on the left within the Automation account.

ibarrau_2-1719347416763.png

For example, we will create the script for Pausing. The code would be similar for Resuming the service, with only the last method changing. Once created, it will guide us to an interface to start writing our Python code. This process is quite straightforward, such as:

ibarrau_3-1719347429150.png

However, remember that exposing keys in code is a serious security issue. It's best to create an Azure KeyVault to store our secrets or IDs securely. To do this, create a KeyVault resource, add your account as Key Vault Administrator, and create the secret. If you want to learn more about this, you can find examples or follow the training: Configure and manage Azure Key Vault.

If using KeyVaults, it would look like this:

ibarrau_4-1719347468588.png

Save and publish. Then, you can execute it to ensure everything works correctly.

Finally, schedule the script to run. If you know the resource usage patterns, schedule runs during times and days when it is not typically used. Go to the runbook and check the "Schedule" menu to follow the instructions as shown in the image:

ibarrau_5-1719347490533.png

This ensures that recurring runs of the code are set up to keep everything in order.

That's how we finish building our Fabric Pause, Power BI Embedded, or Azure Analysis Services using SimplePBI. You would similarly repeat the process to "Resume" the resource, ensuring it starts up when needed.

 

Original post from LaDataWeb