In this lab we will practice In this lab we will practice creating a web app in the Azure
Azure is cloud offering by Microsoft.
Azure offers a large collection of services including
Azure, like other cloud platforms, relies on virtualization.
Most computer hardware can be emulated in software, because most computer hardware is simply a set of instructions encoded in silicon.
Using a virtualization layer that maps software instructions to hardware instructions, virtualized hardware can execute in software as if it were the actual hardware itself.
The cloud is a set of physical servers in datacenter that execute virtualized hardware on behalf of customers.
You have two option to complete this lab
Login to Microsoft
Sign into you Microsoft Account
Click on activate sanbox.
Open a new tab in browser and open https://portal.azure.com
Sign in with Microsoft account you used in previous step.
If you get below message click on X to close it
Else go to next step
Select Create a resource from the Azure portal’s Azure services section. The pane to create a resource appears.
If you don’t see it, in the search box, search for and select Web App.
On the Basics tab, enter the following values for each setting.
Project Details
Subscription
Concierge Subscription
The web app you are creating must belong to a resource group. Here, you select the Azure subscription to which the resource group belongs (or will belong, if you are creating it within the wizard).
Resource Group
From the dropdown list, select [Learn-XXXXX] The resource group to which the web app will belong. All Azure resources must belong to a resource group.
Instance Details
Name Enter a unique name The name of your web app.
This name will be part of the app’s URL: appname.azurewebsites.net.
The name you choose must be unique among all Azure web apps.
Publish Code
The method you want to use to publish your application.
When publishing an application as code, you also must configure Runtime stack to prepare App Service resources to run your app.
Runtime stack Python 3.8
The platform on which your application will run.
Your choice may affect whether you have a choice of operating system - for some runtime stacks, App Service supports only one operating system.
Operating System
Linux The operating system used on the virtual servers that will run your app.
Region Select West US or Central US
The geographical region from which your app will be hosted.
App Service Plan
Linux Plan Accept default
The name of the App Service plan that will power your app.
By default, the wizard will create a new plan in the same region as the web app.
Sku and size F1
The pricing tier of the service plan being created.
This determines the performance characteristics of the virtual servers that power your app, and the features it has access to.
Select Review + Create to go to the review pane
The portal will show the deployment pane, where you can view the status of your deployment.
To preview your web app’s default content, select the URL at the top right.
The placeholder page that loads indicates that your web app is up and running, and is ready to receive deployment of your app’s code.
This step should be done on you local linux machine, we are using cloud shell for this lab.
Click on Cloud Shell link in top right of portal.azure.com as shown below
Enter below command to check Python version is 3.6 or higher
az login
You will get below output
Cloud Shell is automatically authenticated under the initial account signed-in with. Run 'az login' only if you need to use a different account
To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXX to authenticate.
Click on url in output and enter code in below window
In cloud shell you see message similar to below.
[
{
"cloudName": "AzureCloud",
"homeTenantId": "XXXXXXXX",
"id": "XXXXXXX",
"isDefault": true,
"managedByTenants": [],
"name": "Concierge Subscription",
"state": "Enabled",
"tenantId": "604c1504-c6a3-4080-81aa-b33091104187",
"user": {
"name": "[email protected]",
"type": "user"
}
}
]
Clone the sample repository using the following command and navigate into the sample folder.
git clone https://github.com/Azure-Samples/python-docs-hello-world
cd python-docs-hello-world
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
az webapp up --sku B1 --name azure103
You will get messages on creating and deploying webapp
Refresh the browser window where you have site open or open URL Again
You will see below
vi app.py
press i for insert and modify it to look like below
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, World from azure lab 103"
Press escape on keyboard and “:wq” to save and exit from vi
Run below command to redeploy
az webapp up --sku B1 --name azure103
You will get messages on creating and deploying webapp like before
Refresh the browser window where you have site open or open URL Again
You will see that changes we made have been updated
Summary
You’ve successfully created and deployed a web application to Azure App Service.
App Service simplifies managing and controlling your web app in comparison to traditional hosting options.
Your App Service Plan can help you reduce the time and effort spent running and managing your web app, and provide advanced cloud features such as autoscaling and Git integration.
Clean up
The sandbox automatically cleans up your resources when you’re finished with this module.
When you’re working in your own subscription, it’s a good idea at the end of a project to identify whether you still need the resources you created. Resources left running can cost you money.
You can delete resources individually or delete the resource group to delete the entire set of resources.