lunes, 6 de abril de 2020

Create a Logic App to increase the number of instances in one App Service Plan

The purpose of this procedure is to increase the number instances of one WebApp in an automatic way, triggering from one specific http request. For that, one pre-requisite is to have Application Insights enabled for that WebApp.

First, we need to get the App Service Plan configuration in json format. To do that, we can do a REST API call to retrieve the json.

1. Generate the App Service Plan management URL:

     a. In the Azure portal, we navigate to the App Service Plan and copy the URL.

     b. Modify the URL as the example:*****a286c474d612/resourceGroups/ScaleOut_Test/providers/Microsoft.Web/serverFarms/ ASP-ScaleOut***/webHostingPlan d9ec*****a286c474d612/resourceGroups/ScaleOut_Test/providers/Microsoft.Web/serverFarms/ASP-ScaleOut***?api-version=2019-08-01

2. We need to generate a bearer to authenticate. 

     a. An easy way is to use this site: 

     b. Click on TRY IT and authenticate with some credentials valid in the subscription, and you will get a temporary valid token.

3. Now we can use the App Service Plan management URL and the token to retrieve the json. We are going to use the tool Postman:

The next step is to get the information for the API Access of the Application Insights. We got this information in the Azure Portal. The information we need is the Application ID and one valid API Key.

To authenticate the REST API request we will launch to modify the App Service Plan, we are going to use an AAD APP, and we assign Owner permissions to this APP.

Now we can create the Logic App:
1. In the Azure Portal, go to the Logic Apps section and add a new Logic App.

2. The Logic App first trigger will be based in Recurrence:

3. Add and configure a new one step of type Application Insights - Run Analytics Query:

     a. Configure the Application Insights connection with the API Access information

     b. Configure the query we want to execute to see if the request has been registered in the WebApp:

4. Add and configure a new one step of type Control – For Each

     a. Add a Dynamic Content of “Value”:

     b. Add an action of type Control – Condition:

     c. Add a Dynamic Content of “Content_”

     d. And configure the condition as count is greater than or equal to 1

5. In the “If true”  column, add a new HTTP action:

     Configure the HTTP request as the example:

6. In the “If true”  column, add a new SMTP – Send Email (V3) action:

     a. Create an SMTP connection, with your SMTP server/user:

     b. Configure the outgoing email with the parameters you prefer, for example:

7. Finally, save the new Logic App

And if you want to verify if the change in the number of instances has been successful, check in the Web App, the sections Scale Out (App Service Plan) and Process Explorer:

2 comentarios:

  1. Really thanks for sharing this useful post !! This post is very informative and I have got very good information.
    online subscription management