Pause Power BI Embedded with Azure Functions

Power BI Embedded is great for embedding Power BI content into custom applications, websites and portals via an embedded iframe. With its ability to scale up, scale down and even be paused, it is also an excellent way to test out Power BI Premium functionality. If you are in the process of setting up Power BI Premium capacity but are not quite ready to commit to the Premium capacity P SKUs (P1-P3), Power BI Embedded is a great alternative for your development and testing.

Currently, Power BI Embedded offers 6 different nodes/sizes. The cores, memory and infrastructure can vary based on your needs. An A4 Embedded SKU is the equivalent of a P1 Premium SKU and is the minimum required to use Power BI Paginated Reports, but the smaller SKUs (A1-A3) can be used to test other Power BI Premium capabilities. Also, Power BI Embedded can be scaled up or down easily via the Azure portal and can even be paused when you are not using it. This is great for adjusting the performance to suit your needs or even pausing it during off hours to reduce costs.

As with most services available in Azure, there are multiple ways for interacting with your Power BI Embedded service. There is a REST API that provides the ability to create, retrieve, update and delete Power BI dedicated capacities. There are also Power BI Embedded PowerShell Cmdlets that allow you to interact with your Power BI Embedded Capacity and related Workspaces.

In my demo below, I will be using the PowerShell Cmdlets to pause Power BI Embedded using an Azure Function. However, this is only one of the many ways you can use the Power BI Embedded REST API and PowerShell Cmdlets. I chose Azure Functions due to their flexibility of supporting multiple languages as well as the ease of integrating with other Azure services. Also, using the Azure Functions consumption plan, you get 1 millions requests and up to 400,000 GB-s free every month. My function will only run once a day and will not use many resources, so it will run free in my Azure subscription.

If you do not have Power BI Embedded setup, you will need to do that as your first step.

After setting up my Power BI Embedded service, my next step was to create an Azure Function. Since I will be using PowerShell Cmdlets to interact with Power BI Embedded, I chose PowerShell Core as my Runtime Stack.

As discussed previously, I will be using the Consumption plan to take advantage of the free requests/resources. Also, be sure to turn on Application Insights so you can monitor the Azure Function.

Once the Azure Function has been created, the next step is to turn on the System Assigned Managed Identity for the Azure Function. This will allow the function to control Power BI Embedded.

With the Azure Function setup with a system assigned managed identity, the next step is to go to your Power BI Embedded service and add a role assignment to that identity. “Click Access control (IAM)”, then “Add a role assignment”. I used the Owner role in my demo, but you may want to get more granular with your security. The managed identity will have the same name as your Azure Function App Service (mine was faedwglock001).

Now we need to setup the Azure Function. For this demo, I am using the Time Trigger template. The HTTP Trigger is great if you want to send an HTTP request to interact with your function/Power BI Embedded Capacity.

I set my function up to run once daily at 5 PM. The Cron Expression uses UTC time so you will need to adjust accordingly.

Here is the PowerShell script I used. For this demo, it is very basic and checks to see if my Power BI Embedded Capacity is paused. If not, it pauses it using the Suspend-AzPowerBIEmbeddedCapacity cmdlet.

The hardest part of setting this up for me was figuring out how and where to access the PowerShell cmdlets. To find the proper path for my PowerBIEmbedded.psd1, I used the Azure Functions Advanced Tools (Kudu). In the PowerShell Debug Console, I was able to browse the folders and find what I was looking for.

This was a quick demo of how to pause Power BI Embedded using Azure Functions. If this is something you need assistance with or you are looking for someone to help on your Power BI journey, contact us.

Leave a Reply

Your email address will not be published. Required fields are marked *