Restart Azure Web App Using Azure Logic App
Learn how you easy it can be to trigger the Azure Logic app to restart the Azure web app.
Join the DZone community and get the full member experience.
Join For FreeIntroduction
In this article, we are going to see how to restart the Azure web app using Azure Logic App. I am assuming that you know about Azure Logic Apps. If you want to read more about Azure Logic Apps, check out this article.
You may also enjoy: Introducing Azure Logic Apps Integration Service Environment (ISE)
Prerequisites
For creating a Logic App which will restart the Azure web app, you need the following items and access.
- Azure portal access where Azure web App is deployed.
- Tenant Id of your azure account
- Client_id
- Client_secret
- Azure Subscription Id
- Resource Group
- App name
Steps
Restarting of Azure web app using Azure logic app will have three simple steps, as shown below.
We will discuss, figure 1 steps in detail in the following section.
Start Designing of the Azure Logic App
Step 1 - Get Access Token (HTTP)
Firstly, we need to add the HTTP action in-order to generate and get the access token. This action is having a post method and requires tenant_id, client_id, client_secret.
"method": "POST"
"uri": "https://login.microsoftonline.com/{tenant_id}/oauth2/token"
"body": "&client_id={client_id} &client_secret{client_secret}&://management.core.windows.net/"
"Content-Type": "application/x-www-form-urlencoded"
Figure 2
After execution, we will get a JSON result which will have an access_token value which is required to restart the app.
JSON result looks like as below:
Step 2: Parse JSON
Parse the JSON and get the body and define the schema using the sample payload to generate the schema.
Step 3 - Restart App (HTTP)
For this HTTP request, we need a subscription ID, resource group, and app name of the Azure web app. We need to pass the access_token
from the previous step in the Authorization field.
"method": "POST"
"uri": "https://management.azure.com/subscriptions/{subscription_id}/resourceGroups/{resource_group}/providers/Microsoft.Web/sites/{webApp_name}/restart?-08-01"
"Authorization": "Bearer @{body('Parse_JSON')?['access_token']}",
"Content-Type": "application/json"
Run Logic App
Your Logic app is ready and now run this and see the results in history.
The Activity Log of Web App
Check the webApp activity log. You might need to wait for 1-2 mins in-order to update this.
Expected Result
The Logic app is configured properly and worked as per expected. It is restarting the Azure web app, and we can configure this on-demand and schedule it. For on-demand, we can use email receiving event and restart it on receiving an email with a specific subject line. This process is presented below.
Automate the Logic App on Receiving an Email
To automate this process, we can configure the above Logic app to receive an email with some defined text in the subject. Now, whenever you will receive an email with a defined subject then the Logic app will run automatically.
Summary
In the above article, we saw how to restart the Azure web app using the logic app. We also saw how to use email receiving an event to restart the app. Apart from the restart, we can perform many more operations like stop, start, etc. For more triggered APIs, refer to the below URL and configure those in the above logic app accordingly.
Further Reading
Is Logic Apps or Durable Functions Best for Your Workflow?
Azure Logic Apps (With Demo Using YouTube and Outlook.com Connectors)
Opinions expressed by DZone contributors are their own.
Comments