You will learn:
- Login and work with Azure Portal
- Working with Azure CLI
- Building a simple Flask application
- Deploying a Python Flask application without a container
- Configuring, monitoring, and updating a live Azure Web App
Access "Azure Dev Tools for Teaching"
To create an account, use the Azure for Students page.
Click the green Start free button, then click Sign in.
When prompted to sign in, log in similarly to MAIS. Use the ad.tuke.sk prefix:
ad.tuke.sk\ab123cd
PASSWORD
You may be required to enter a phone number for SMS verification (MFA).
After verification, open the Azure Portal.
Check the Azure CLI
Open a WSL2 Ubuntu terminal. Install the latest version of Azure CLI (requires Python 3).
Azure CLI should now be available in your environment:
az --version
Login to Azure
Create a connection with your account on the Azure cloud. Login and authentication will take place using a web browser:
az login
If for some reason a graphical web browser does not work, use
az login --use-device-code
Then open a web browser and enter the displayed device code.
Check which subscription is active:
az account show
Working with Azure CLI
Azure CLI can replace the web interface. Although the command line is less intuitive at first glance, we can save deployment commands to files, archive, share, and repeat them.
After the basic az command there is another command that has additional subcommands and arguments.
For example
az resource list
lists the currently deployed resources. The output will be in JSON format. This format is easy to parse, e.g. in Python, or using the jq utility.
Using the --help switch, you can display help for each command.
Familiarize yourself with Azure Web App Services
Before using the cloud service, you should familiarize yourself with it.
Azure Web App Services can simplify deploying code to an Azure production environment, and managing/scaling applications without having to build a Docker container image yourself. Depending on the deployment method, App Service builds and runs your app for you.
Create the Flask Application
In this step, you will create a local repository with all necessary files for local development.
Create a project folder:
mkdir flask-az-cli
cd flask-az-cli
Create a virtual environment:
python -m venv venv
Activate it:
source venv/bin/activate
Install Flask and Gunicorn:
pip install flask gunicorn
Create a file named app.py:
from flask import Flask
import os
app = Flask(__name__)
@app.route("/")
def home():
return "Hello from Azure Web App!"
@app.route("/about")
def about():
return "This is a Flask app deployed using Azure CLI."
if __name__ == "__main__":
app.run(host="0.0.0.0")
Create requirements.txt:
pip freeze > requirements.txt
Note: The
venv/folder is automatically excluded from deployment byaz webapp up. You can also create a.webappignorefile listing any other paths to exclude.
Verify it contains at least (versions may differ):
Flask==3.x.x
gunicorn==xx.x.x
You can check with:
pip freeze | grep -iE "flask|gunicorn"
Test locally:
python app.py
Open http://127.0.0.1:5000 in your browser to verify the app works, then stop the server (CTRL+C) before continuing.
Deploy Using Azure CLI
In simple scenarios, the whole application can be made public with one command. Inside the project folder, run:
az webapp up \
--name <unique-app-name> \
--runtime "PYTHON:3.12" \
--sku B1 \
--location westeurope \
--resource-group <resource-group>
Replace <unique-app-name> with something globally unique (e.g. flaskstudent12345) and <resource-group> with a name of your choice (e.g. flask-rg).
This command performs multiple steps automatically:
- Creates a resource group (if needed)
- Creates an App Service plan
- Creates the Web App
- Deploys your code as a ZIP package
Note: The auto-created resource group name will be shown in the command output. Record it — you will need it in later steps. You can also retrieve it with:
az webapp show --name <unique-app-name> --query resourceGroup --output tsv
It will take some time to deploy. If everything went well, your application will appear at the URL assigned to it by Azure.
Test the Application
Open in your browser:
https://<unique-app-name>.azurewebsites.net
You should see:
Hello from Azure Web App!
Improve the Application
Configure Gunicorn
Azure can use the Gunicorn WSGI server in production. Configure the startup command:
az webapp config set \
--name <unique-app-name> \
--resource-group <resource-group> \
--startup-file "gunicorn --bind=0.0.0.0 --timeout 600 app:app"
To find the resource group name:
az webapp list --output table
Update and Redeploy
To update and redeploy, modify app.py, for example:
@app.route("/")
def home():
return "Updated version deployed without Git!"
Redeploy:
az webapp up
Note: On subsequent runs,
az webapp upre-uses the settings saved in.azure/config— no flags needed.
Set Environment Variables
Use Azure CLI to set an environment variable:
az webapp config appsettings set \
--name <unique-app-name> \
--resource-group <resource-group> \
--settings GREETING="Hello from Azure Environment!"
Modify the home() function in app.py:
return os.environ.get("GREETING", "Default message")
Redeploy and test.
Enable Logging
az webapp log config \
--name <unique-app-name> \
--resource-group <resource-group> \
--application-logging filesystem
Refresh the browser, then stream logs:
az webapp log tail \
--name <unique-app-name> \
--resource-group <resource-group>
Clean Up Resources
At the end, don't forget to clean up to avoid consuming your credits:
az group delete --name <resource-group> --yes --no-wait