How to deploy a web application in Azure App Service?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In today’s blog post, we will discuss how to deploy a Python App (basic REST API) using Azure App Service.
How to deploy a web application in Azure App Service?
Prerequisites:
Azure CLI installed and configured
Step 1: Clone the basic REST API code written in Python.
1 2 3 4 5 |
## Clone Python REST API code git clone https://github.com/CloudAffaire/rest.git ## Get inside the local repository cd rest |
Step 2: Create a new resources group for your Azure app service.
1 2 3 4 |
## Create a new Azure resource group az group create \ --name AppServiceDemoRG \ --location westindia |
Step 3: Deploy a Python basic REST API using Azure App Service.
1 2 3 4 5 6 7 |
## Deploy your Python app using Azure web service az webapp up \ --location westindia \ --name AppServiceDemoRestApi \ --runtime 'PYTHON:3.8' \ --resource-group AppServiceDemoRG \ --sku B1 |
The above command will do the following things
- Create a default app service plan.
- Create an app with the specified name.
- Zip deploy files from the current working directory to the web app.
It may take 2-3 mins to create all the resources and deploy your Python web app using Azure App Service.
Step 4: Validate if the REST API is working fine.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
## Test your REST API endpoint curl https://appservicedemorestapi.azurewebsites.net ## Returns ## { ## "Message": "Welcome to REST API Version 1" ## } curl --request GET \ https://appservicedemorestapi.azurewebsites.net/api/v1.0/employees ## Returns ## { ## "employees": [ ## { ## "email": "debjeettoni@gmail.com", ## "firstName": "Debjeet", ## "id": 1, ## "lastName": "Bhowmik", ## "phone": "9748239852" ## }, ## { ## "email": "chandrima@gmail.com", ## "firstName": "Chandrima", ## "id": 2, ## "lastName": "Koley", ## "phone": "1111111111" ## } ## ] ## } curl --request GET \ https://appservicedemorestapi.azurewebsites.net/api/v1.0/employees/1 ## Returns ## { ## "employee": { ## "email": "debjeettoni@gmail.com", ## "firstName": "Debjeet", ## "id": 1, ## "lastName": "Bhowmik", ## "phone": "9748239852" ## } ## } curl --request POST \ --data '{ "id": 3, "firstName": "Alex", "lastName": "Farguson", "email": "alex@gmail.com", "phone": "9876543210" }' \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ https://appservicedemorestapi.azurewebsites.net/api/v1.0/employees ## Returns ## { ## "employees": [ ## { ## "email": "debjeettoni@gmail.com", ## "firstName": "Debjeet", ## "id": 1, ## "lastName": "Bhowmik", ## "phone": "9748239852" ## }, ## { ## "email": "chandrima@gmail.com", ## "firstName": "Chandrima", ## "id": 2, ## "lastName": "Koley", ## "phone": "1111111111" ## }, ## { ## "email": "alex@gmail.com", ## "firstName": "Alex", ## "id": 3, ## "lastName": "Farguson", ## "phone": "9876543210" ## } ## ] ## } curl --request PUT \ --data '{ "firstName": "Kunal", "lastName": "Sharma", "email": "kunal@gmail.com", "phone": "1234567899" }' \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ https://appservicedemorestapi.azurewebsites.net/api/v1.0/employees/3 ## Returns ## { ## "employee": { ## "email": "kunal@gmail.com", ## "firstName": "Kunal", ## "id": 3, ## "lastName": "Sharma", ## "phone": "1234567899" ## } ## } curl --request DELETE \ https://appservicedemorestapi.azurewebsites.net/api/v1.0/employees/3 ## Returns ## { ## "result": true ## } |
You can also check in Azure Portal under Azure App Services
Step 5: Clean up.
1 2 3 4 |
## Delete the resource group az group delete \ --name AppServiceDemoRG \ --yes |
Hope you have enjoyed this article. To get more details on Azure App Service, please refer to the below documentation.
https://docs.microsoft.com/en-us/azure/app-service/
Azure App Service CLI reference
https://docs.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest