How to Pause or Start Microsoft Fabric Capacity Automatically

By:   |   Updated: 2023-09-01   |   Comments (7)   |   Related: 1 | 2 | 3 | > Microsoft Fabric


Problem

I created a Microsoft Fabric capacity in Azure and assigned it to a workspace. I understand that if the capacity is paused, this will save me on cost since the capacity is billed for the duration it is running. However, it's not feasible to manually start or pause this capacity manually each time. Is there a way to automate this?

Solution

For an introduction to Microsoft Fabric and its capacities, check out the following tips:

Unfortunately, at the time of writing, there are no dedicated Microsoft Fabric REST API endpoints to help us with this automation job. There is a Power BI REST API for capacities, but it's unrelated to Fabric capacities (at least not the Azure F-SKU you can pause/resume). Luckily, we still have the REST APIs of Azure itself. This tip will show how to use the Azure REST API to start a paused capacity. Hopefully, a dedicated Microsoft Fabric REST API will be available in the future.

We'll use Azure Data Factory (ADF) as the tool of choice to start the Fabric capacity. You can also use other services, such as Azure Functions or Azure Logic Apps, but the principles remain the same. You could also use a Fabric data pipeline (which is similar to using ADF). The problem is that you cannot use a Fabric pipeline to start a capacity if the pipeline belongs to a workspace with the same capacity assigned. This would mean you would need multiple capacities, where there's one capacity used to start/pause the other capacities. Having such a capacity continuously running comes with a cost. It's much cheaper to use ADF or any other services, but as a downside, not everything will be centralized in Microsoft Fabric.

Resume a Capacity with the Azure REST API

For an introduction to ADF, check out this tutorial. Create a new pipeline and add a Web activity to the canvas. Next, add three parameters to the pipeline:

  1. Subscription – This is the guide to the subscription hosting the capacity.
  2. Resourcegroup - This is the name of the resource group that contains the capacity.
  3. Capacity – This is the name of the capacity.

Having these values parameterized will be helpful if you want to pause/resume multiple capacities (and you want your pipeline being called from a For Each loop) or if you are deploying the pipeline from one environment to another.

pipeline parameters

As a first step, we will check the pipeline to see if the capacity is already running.

web activity to fetch capacity status

We can do this by calling the Microsoft.Fabric/capacities endpoint. For the URL property, configure the following expression:

https://management.azure.com/subscriptions/@{pipeline().parameters.subscription}/resourceGroups/@{pipeline().parameters.resourcegroup}/providers/Microsoft.Fabric/capacities/@{pipeline().parameters.capacity}?api-version=2022-07-01-preview

Make sure there are no typos in the URL. This can result in unexpected errors. For example, I made a small mistake in the API version, and the following error was returned:

no registered resource provider found for type capacities

The Web activity will use the GET HTTP method to retrieve the capacity status. As for the authentication, it's easiest to use the system-assigned management identity of the ADF instance. As the resource, we need to use https://management.azure.com.. The Web activity has the following configuration:

get capacity status web activity config

To start or pause a capacity, contributor permissions are required on the capacity level. In the Azure portal, go to the capacity and then to Access Control (IAM). Assign the ADF managed identity to the contributor role.

access control of the capacity in Azure portal

If the needed permissions are missing, the following error is returned:

does not have authorization to perform action microsoft.fabric/capacities/resume/action

For the moment, it's not possible to add this specific action to a custom role, so the contributor role is the bare minimum.

When we debug the pipeline, the following output will be returned by the Web activity:

output of web activity

The state property is the one we need. In the screenshot, the value is Active, which means the capacity is running. A state of Paused is returned when the capacity is not running. Other information is also returned, such as the capacity admin, the location, and the current SKU of the capacity.

Let's add an If condition to the canvas and connect it to the Web activity. We will use this condition to check if the capacity is running or not based on the output of the Web activity. You can use the following expression:

@equals(activity('Get Capacity Info').output.properties.state,'Paused')

If the expression returns true, the capacity is paused and needs to be started. In the True section of the condition, add another Web activity. This time we will use a POST message to the REST API to start the capacity.

full pipeline with two web activities and an if condition

In the Web activity, use the following expression for the URL:

https://management.azure.com/subscriptions/@{pipeline().parameters.subscription}/resourceGroups/@{pipeline().parameters.resourcegroup}/providers/Microsoft.Fabric/capacities/@{pipeline().parameters.capacity}/resume?api-version=2022-07-01-preview

This time we're calling the resume endpoint. The method is set to POST, and a dummy body is specified. The same settings are used for the authentication as in the other Web activity.

configuration of resume activity

When we debug the pipeline, we see the Web activity calls the API to start the capacity.

pipeline when a paused capacity is started

If the capacity is already running, the Web activity inside the If condition is not executed:

pipeline when capacity is already running

Keep in mind that the API call is asynchronous, meaning ADF will not report if there was an error starting the capacity. A succeeded Web activity means the API call was successfully made but doesn't necessarily mean the capacity is started. You could extend the pipeline with a Wait activity and then another Web activity that checks if the capacity has actually started.

If you want to pause a capacity, you can use the suspend endpoint. A good use case for a pipeline that shuts down a capacity is one that runs at the end of every business day. This would prevent unnecessary costs if the capacity would run all night with no one to use it.

Conclusion

In this tip, we've shown you how to build a simple pipeline in ADF that will resume a paused Fabric capacity. A Fabric capacity cannot start itself, so it's not possible to build a Fabric pipeline where you start your one and only capacity. You would need another capacity or a P-SKU capacity; both incur extra costs.

The downside of this functionality in ADF (or another tool like Azure Logic Apps) is that not all logic is consolidated in Microsoft Fabric itself.

Next Steps


sql server categories

sql server webinars

subscribe to mssqltips

sql server tutorials

sql server white papers

next tip



About the author
MSSQLTips author Koen Verbeeck Koen Verbeeck is a seasoned business intelligence consultant at AE. He has over a decade of experience with the Microsoft Data Platform in numerous industries. He holds several certifications and is a prolific writer contributing content about SSIS, ADF, SSAS, SSRS, MDS, Power BI, Snowflake and Azure services. He has spoken at PASS, SQLBits, dataMinds Connect and delivers webinars on MSSQLTips.com. Koen has been awarded the Microsoft MVP data platform award for many years.

This author pledges the content of this article is based on professional experience and not AI generated.

View all my tips


Article Last Updated: 2023-09-01

Comments For This Article




Thursday, February 15, 2024 - 6:28:06 AM - Pepe Potamo Back To Top (91948)
To suspend:

https://management.azure.com/subscriptions/<subs>/resourceGroups/<rg>/providers/Microsoft.Fabric/capacities/<capacity>/suspend?api-version=2022-07-01-preview

Sunday, December 17, 2023 - 9:16:56 AM - Koen Verbeeck Back To Top (91803)
Hi Julien,

you're using the regular Azure API. In order to make it work, I had to add ADF as a contributor to the Fabric capacity. You might have to do the same thing with your app.

Regards,
Koen

Sunday, December 17, 2023 - 9:15:01 AM - Koen Verbeeck Back To Top (91802)
Hi Sumeet,
I mention at the end of the article that the suspend endpoint should be used.

Regards,
Koen

Friday, December 15, 2023 - 5:48:27 AM - Sumeet Gadade Back To Top (91800)
Worked great with - https://management.azure.com/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Fabric/capacities/xxx/suspend?api-version=2022-07-01-preview

Thanks a ton!

Friday, December 15, 2023 - 5:42:04 AM - Sumeet Gadade Back To Top (91799)
Resume activity works fine.
Pause acivity does not work, using the api call - https://management.azure.com/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Fabric/capacities/xxx/pause?api-version=2022-07-01-preview
Return 404 error code.
Any help is appreciated. Thanks in advance.

Sunday, October 8, 2023 - 6:10:52 PM - Julien Back To Top (91634)
Hi, i am trying to make it work programmatically, making API call. I need in the Header , in the Autorisation , the token.
I have created an app, and I can get the token from this app. But , still get the error message :

code":"AuthorizationFailed","message":"The client 'XXX' with object id 'XXX' does not have authorization to perform action
| 'Microsoft.Fabric/capacities/read'
In the API permission of the app, there is not Fabric api available. Only POWER BI capacity, but it doesn't work.
What are the API permission we have to add for an Application ? thank you.

Monday, September 4, 2023 - 12:47:37 PM - Thomas Back To Top (91528)
I tried the demo and it worked as explained!!!