0

I'm trying to use Azure Logic App to create an automation that sets the number of always ready instances to 1 during weekends and back to 3 during working days. Note that my function app is hosted in an Elastic Premium Plan EP1. I have been struggling on this task but at the end I was not able to solve it. Also I didn't find any documentation for creating this automation. Do you have any idea if it is possible to do this?

Function page for scaling out

Gregory
  • 75
  • 1
  • 7
  • I think it would help if you referenced (with a screenshot) the setting you’re talking about wanting to control. Might help people help you. – Skin May 25 '23 at 21:04

2 Answers2

1

After reproducing from my end, I could get this done using Azure Automation Account. I have set the days that I wanted in Logic Apps and made a call to execute the below script based on the day.

First of all navigate to the "Automation Accounts" service from the console, if you don't have any automation accounts yet, create one pressing the button "create":

Automation account creation

Then you create two runbooks under "Process Automation" section:

runbooks creation

Using this PowerShell scripts:

runbook1 script for Weekdays

$resourceGroupName = "<YOUR_RESOURCE_GROUP>"
$functionApp = "<FUNCTION_APP>"

$Resource = Get-AzResource -ResourceGroupName $resourceGroupName -ResourceName $functionApp/config/web -ResourceType Microsoft.Web/sites
$Resource.Properties.minimumElasticInstanceCount = 3
$Resource | Set-AzResource -Force

runbook2 script for Weekends

$resourceGroupName = "<YOUR_RESOURCE_GROUP>"
$functionApp = "<FUNCTION_APP>"

$Resource = Get-AzResource -ResourceGroupName $resourceGroupName -ResourceName $functionApp/config/web -ResourceType Microsoft.Web/sites
$Resource.Properties.minimumElasticInstanceCount = 1
$Resource | Set-AzResource -Force

Don't forget to "save" and then "publish" the runbooks.

Save and then publish the runbook

Then navigate to Logic apps service from the console and create a new instance, then go to "logic apps designer". Here is the flow of my logic app:

enter image description here

In the True and False boxes search for "create job":

create job

Note that when you create the job, you will need to authenticate using one of the available authentication methodologies, I have selected "OAuth default", then you simply paste the tenantID

enter image description here

Results:

enter image description here

Brian H.
  • 2,092
  • 19
  • 39
SwethaKandikonda
  • 7,513
  • 2
  • 4
  • 18
  • Thank you @SwethaKandikonda, it is working properly and your answer was very useful. If now I wanted to change the automation in order to set the number of always ready instances to 1 also during the week days nights, should I have to change the PowerShell code or it is just a matter of changing the "recurrence" box from the logic app designer? Because at the end I need 3 always ready instances only during business hours of week days. – Gregory Jun 05 '23 at 12:08
  • @Gregory, you need to change the powershell code for this taking nights also into consideration along with the weekends. One way to achieve this is to run the flow twice per day taking day or night condition and make the respective block of code run. – SwethaKandikonda Jun 05 '23 at 12:17
  • Sorry @SwethaKandikonda I just noticed from the logs of "Job stream details" in the runbook console that the "minimumElasticInstanceCount" is not found. I get this error: "The property 'minimumElasticInstanceCount' cannot be found on this object. Verify that the property exists and can be set. At line:5 char:1 + $Resource.Properties.minimumElasticInstanceCount = 3 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound" – Gregory Jun 05 '23 at 12:44
  • Ok I solved this problem in another question, this is the link: "https://stackoverflow.com/questions/76454527/azure-automation-and-logic-apps-for-scheduled-auto-scaling-of-function-app" – Gregory Jun 14 '23 at 14:33
1

For the sake of completeness, in the following, a configuration that sets the number of always ready instances to 3 during business hours of week days, and 1 always ready instance during weekend days and out of business hours:

Logic App condition

Gregory
  • 75
  • 1
  • 7