Skip to content

A simple Python Flask server (classroom example). Designed to be run with Flask locally and deployed to Azure App service.

Notifications You must be signed in to change notification settings

john0isaac/simple-flask-app-terraform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

page_type languages products urlFragment name description
sample
azdeveloper
python
terraform
html
azure
azure-app-service
azure-monitor
simple-flask-app-terraform
Simple Flask (Python) Web App (Terraform) on Azure
A simple Python Flask website, made for demonstration purposes only, and deployed to Azure App service. Uses Azure Developer CLI (azd) to build, deploy, and monitor.

Simple Flask (Python) Web App (Terraform) on Azure

Open in GitHub Codespaces

This repository includes a simple Python Flask website, made for demonstration purposes only. The project can be developed locally with Flask and can be deployed to Azure App Service using the infrastructure files in infra. See below for more details.

Local development

This project has Dev Container support, so you can open it in GitHub Codespaces or local VS Code with the Dev Containers extension.

Steps for running the server:

  1. (Optional) If you're unable to open the devcontainer, create a Python virtual environment and activate that.

  2. Install the requirements:

    python3 -m pip install -r requirements.txt
  3. Run the local server:

    python3 -m flask --debug run --port 50505
  4. Click 'http://127.0.0.1:50505' in the terminal, which should open the website in a new tab.

  5. Try the index page, try '/hello?name=yourname', and try a non-existent path (to see 404 error).

Prerequisites

This template will create infrastructure and deploy code to Azure. If you don't have an Azure Subscription, you can sign up for a free account here. Make sure you have a contributor role to the Azure subscription.

The following prerequisites are required to use this application. Please ensure that you have them all installed locally.

Deployment

This repo is set up for deployment on Azure App Service using the configuration files in the infra folder.

Steps for deployment:

  1. Run the following command to download the project code:

    azd init -t john0isaac/simple-flask-app-terraform
  2. Login to Azure Developer CLI:

    azd auth login
  3. Login to Azure using Azure CLI:

    az login --use-device-code
  4. Provision and deploy all the resources:

    azd up

    It will prompt you to provide an azd environment name (like "flaskapp"), select a subscription from your Azure account, and select a location (like "eastus"). Then it will provision the resources in your account and deploy the latest code. If you get an error with deployment, changing the location can help, as there may be availability constraints for some of the resources.

When azd has finished deploying, you'll see an endpoint URI in the command output. Visit that URI, and you should see the front page of the app! 🎉

Note

When you've made any changes to the app code, you can just run:

azd deploy

Application Architecture

This application utilizes the following Azure resources:

Here's a high-level architecture diagram that illustrates these components. Notice that these are all contained within a single resource group, that will be created for you when you create the resources.

"Application architecture diagram"

This template provisions resources to an Azure subscription that you will select upon provisioning them. Please refer to the Pricing calculator for Microsoft Azure and, if needed, update the included Azure resource definitions found in infra/main.tf to suit your needs.

Next Steps

At this point, you have a complete application deployed on Azure. But there is much more that the Azure Developer CLI can do. These next steps will introduce you to additional commands that will make creating applications on Azure much easier. Using the Azure Developer CLI, you can monitor your application, and test and debug locally.

  • azd deploy to upload the changes to your application code to Azure.

  • azd monitor - to monitor the application and quickly navigate to the various Application Insights dashboards (e.g. overview, live metrics, logs)

  • azd down - to delete all the Azure resources created with this template.

About

A simple Python Flask server (classroom example). Designed to be run with Flask locally and deployed to Azure App service.

Topics

Resources

Stars

Watchers

Forks

Languages