In the previous blog post, I explained Microsoft Fabric capacities, shedding light on diverse capacity options and how they influence data projects. We delved into Capacity Units (CUs), pricing nuances, and practical cost control methods, including manually scaling and pausing Fabric capacity. Now, we’re taking the next step in our Microsoft Fabric journey by exploring the possibility of automating the pause and resume process. In this blog post, we’ll unlock the secrets to seamlessly managing your Fabric Capacity with automation that helps us save time and resources while optimising the usage of data and analytics workloads.
Right off the bat, this is a rather long blog, so I added a bonus section at the end for those who are reading from the beginning to the end. With that, let’s dive in!
As we have learned in the previous blog post, one way to manage our Fabric capacity costs is to pause the capacity while not in use and resume it again when needed. While this can help with cost management, as it is a manual process, it is prone to human error, which makes it impractical in the long run.
A more practical solution is to automate a daily process to pause and resume our Fabric capacity automatically. This can be done by running Azure Management APIs. Depending on our expertise, there are several ways to achieve the goal, such as running APIs on running the APIs via PowerShell (scheduling the runs separately), running the APIs via CloudShell, creating a flow in Power Automate, or creating the workflow in Azure Logic Apps. I prefer the latter, so it is the method that this blog post explains.
Automating Pause and Resume Fabric Capacity with Azure Logic Apps
Here is the scenario: we are going to create an Azure Logic Apps workflow that automatically does the following:
- Check the time of the day
- If it is between 8 am to 4 pm:
- Check the status of the Fabric capacity
- If the capacity is paused, then resume it, otherwise do nothing
- If it is after 4 pm and before 8 am:
- Check the status of the Fabric capacity
- If the capacity is resumed, then pause it, otherwise do nothing
Follow these steps to implement the scenario in Azure Logic Apps:
- Login to Azure Portal and search for “Logic App“
- Click the Logic App service
This navigates us to the Logic App service. If you currently have existing Logic Apps workflows, they will appear here.
- Click the Add button
- On the Basics tab, select the desired Azure Subscription
- Select a desired Resource Group. If you do not have any resource groups, click Create new to create one
- Type in a name in the **Logic App name ** textbox
- Select the desired Region from the dropdown
- Select Consumption on the Plan type
- Keep the Zone redundancy Disabled
- If you want/need to add Tags, click the Next: Tags button, otherwise click the Preview + create button
- Click the Create button
This will create a new Logic App workflow. After the service is created a new Go to resources button.
- Click the Go to resources button
- Click the Logic app designer from the Development Tools section on the left pane or click the Edit button to open the Logic app designer
- Click the Recurrence from the Start with a common trigger section. This opens the Logic app designer and adds the Recurrence trigger
- Change the Interval to 1
- Change the Frequency to Hour
So far, we defined a trigger to run the workflow every hour. The next step is to get the current time.
- Click the New step button
- Search and select the Current time action
The Current time action gets the current time in UTC.
If you live in a different timezone, you need to convert the output from UTC to your timezone.
- Click the New step button, search and select Convert time zone action
- Click the Base time textbox then select the Current time from the Dynamic content
- Select (UTC) Coordinated Universal Time from the Source time zone dropdown
- Select the Destination time zone from the dropdown
- Type in HH:mm in the Format string text box and click Use ‘HH:mm’ as custom value
So far, we got the current time and converted it into our local timezone. Next, we need to get the status of the Fabric capacity. This can be done via the Azure Resource Manager operation by using its Read a resource action.
- Click the New step button, search and select Read a resource action (which is an Azure Resource Manager action)
- Pass your credentials on the Azure Resource Manager operation then select the Subscription of your Fabric capacity from the dropdown
- Select the Resource Group containing your Fabric capacity
- Select Microsoft.Fabric from the Resource Provider dropdown
- Type in capacities/YOUR_FABRIC_CAPACITY_NAME on the Short Resource Id text box where the YOUR_FABRIC_CAPACITY_NAME is the name of your Fabric capacity which in my case is dv01fabric
- Type in 2023-11-01 on the Client Api Version text box
So far, we have the current time for our timezone and the current status of our Fabric capacity. Next, we need to check the current time to see if it’s between 8 am and 4 pm, then resume the capacity if its status is Paused and do nothing if the capacity is already running. If it is after 4 pm and before 8 am, pause the capacity if its status is Resumed, and do nothing if it is already paused.
Let us continue…
- Click the New step button, search for Condition action and select it under the Control operation
- Click the first condition’s textbox to select the Converted time from the Dynamic content
- Change the condition to is greater than or equal to
- Type 08:00 for the value
- Click the Add button
- Select the Add row option
- Select the Converted time from the Dynamic content again
- Select is less than or equal to condition
- Type 16:00 for the value
OK! Let’s take a moment to understand where we are at now. By adding the Condition action, we are checking if the current time is between 8 am and 4 pm.
Next, we need to check the status of the Fabric capacity. If we run the workflow now (click the Run Trigger button, then click Run) and look at the outputs of the Read a resource action containing the state of the capacity under the Properties. That is exactly what we are after. To the value of the state, we need to use the following expression:
With that, let’s continue.
- Click the Add an action button on the True output to add a new Condition action which by default is named Condition 2
- Within Condition 2 click the Choose a value setting
- Copy and paste the above expression into the Expression box
- Click OK
- Set the condition to is equal to
- Type Paused in the Value textbox
- Click the Add an action button on the True output of Condition 2 and add the Invoke resource operation
- On the Invoke resource operation action, select the desired Subscription
- Select the desired Resource Group
- On the Resource Provider select Microsoft.Fabric
- Type in capacities/YOUR_FABRIC_CAPACITY_NAME on the Short Resource Id text box where the YOUR_FABRIC_CAPACITY_NAME is the name of your Fabric capacity, which in my case is dv01fabric
- Type in 2023-11-01 on the Client Api Version textbox
- Type resume on the Action name textbox
So far, we have checked the current time of the day; if it is between 8 am and 4 pm, we check the status of our Fabric capacity. If it is Paused, we resume the capacity. The next step is to add a similar condition to what we’ve done, but this time for the False output of the first Condition action. We just need to repeat steps 39 to 51 with a minor change in step 51 where we type suspend on the Client Api Version textbox.
The following image shows the entire solution. Just so you know, I renamed the actions with more proper names.
Here you go! You have it.
Since you have come thus far, the following bonus section would add more value. So continue reading…
You can improve the solution to fit your requirements. For example, you can check if the current date is during the weekend, then do not run the workflow.
To do so, follow these steps:
- Click the ellipsis button of the Recurrence trigger
- Click Settings
- Click the Add button under the Trigger Conditions section
- Enter the
@contains('12345', string(dayOfWeek(convertFromUtc(utcNow(), 'New Zealand Standard Time'))))expression
- Click the Done button
The above process forces the trigger to run the workflow only during the weekdays (not on the weekends).
The expression in point 4 gets the curent date and time in UTC, converts it into New Zealand timezone, gets the week day number of the week, and converts it to string. At last, it checks if the day number of the week is in week days. Sunday is 0, Monday is 1 etc…
If you live in a different timezone, you can find Microsoft’s default timezones here.
In this exploration of Microsoft Fabric capacities and Azure Logic Apps automation, we’ve advanced from manual pausing and resuming to an automated solution. By creating a Logic Apps workflow, we’ve demonstrated the practicality of managing Fabric capacity based on a set schedule, optimising resource utilisation effortlessly. In the bonus section, we looked at the solution’s adaptability to specific needs, like excluding weekends.