Day 15: Azure Az-900 Series: Everything About Azure App Service(Part 2)

Day 15: Azure Az-900 Series: Everything About Azure App Service(Part 2)

A Step-by-Step Guide to Launching Your Python Web App on Azure App?Service

The cloud offers unparalleled scalability and flexibility for web applications, but navigating deployment options can sometimes feel overwhelming. This blog post tackles that challenge by providing a detailed walkthrough of deploying a Python web app to Azure App Service.


Why Azure App?Service?

Azure App Service is a Microsoft cloud platform that simplifies web app deployment and management. It offers a variety of features, including:

  • Pre-built runtimes: Azure App Service supports various languages and frameworks, including Python,?.NET, Node.js, and Java. This eliminates the need to manage your own infrastructure, allowing you to focus on application development.
  • Scalability: Easily scale your app up or down based on traffic demands. Azure App Service handles the underlying infrastructure, ensuring your app remains performant even during peak usage.
  • Global reach: Deploy your app in various regions around the world, bringing your application closer to your target audience and reducing latency.
  • Integration with DevOps tools: Azure App Service seamlessly integrates with popular DevOps tools like GitHub Actions and Azure DevOps, enabling streamlined deployment workflows.

Before We?Begin

Before diving into the deployment process, let’s ensure a app service is activated within your Azure subscription. App Service utilises a resource provider, essentially a component that manages specific Azure services.

  1. Accessing Resource Providers: Navigate to your Azure subscription in the Azure portal. This is the central hub where you manage all your Azure resources.
  2. Locating App Services: On the left-hand menu, click on Resource providers. This displays a list of all available resource providers within your subscription.

3. Activating the Service (if necessary): Search for “web” in the search bar. It should be listed under Microsoft.Web. If it’s not registered (which is unlikely for new accounts), click on it and hit Register to activate it. This ensures you have the necessary resources to create and manage App Services.

Creating Your Azure App?Service

Now that we’ve prepared the groundwork, let’s create the App Service that will host your Python web application:

  • Search and Select: In the Azure portal search bar, type “App Services” and select the service from the dropdown menu.

  • Adding a New App Service: Click the Add button to initiate the creation of a new App Service.

  • Giving it a Name: Choose a unique and memorable name for your App Service. This will be part of the public URL users will access your application through, so pick something descriptive.
  • Operating System Selection: Since we’re deploying a Python web app, select Linux for the operating system. While Azure App Service supports Windows for certain functionalities, Linux is the preferred choice for Python applications.
  • Location: Select a region closest to your target audience. This helps ensure optimal performance and reduces latency for your users. For instance, if you expect most users to be in the USA, choose a region like East US. I am based in the UK so I will choose UK South.

  • Choosing the Right Pricing Tier: Azure App Service offers various pricing tiers that cater to different needs. For development purposes, the Free tier is a great starting point. However, keep in mind that the free tier has limitations on CPU, memory, and uptime. Carefully review the pricing details on the Azure website (as there may be discrepancies between the portal and the pricing page) to choose a tier that aligns with your application’s requirements and expected usage. Consider factors like traffic volume and resource needs when making your selection. Link to the pricing page: https://shorturl.at/fnLUX

  • Deployment Options: Under Deployment Center, select Code. This indicates that we’ll be deploying our application code directly from a source control repository. You can connect it with you GitHub account for continous deployment.?

  • Runtime Stack: Keep the default Python selection for the runtime stack. Azure App Service provides pre-configured runtime environments optimised for specific languages and frameworks. Choosing Python ensures your application has the necessary libraries and dependencies pre-installed for smooth operation.
  • Clicking Next: Networking (Optional): Deployment slots, a feature that allows you to stage new application versions before deploying them to production, require a paid tier. If you don’t plan on using deployment slots for now, you can skip this step and proceed to the next section.

  • Review and Create: Double-check all the configurations you’ve made. Once you’re satisfied, click Review + create to provision your new Azure App Service resource. This process might take a few minutes to complete.

  • Once created, this will be you Web App Dashboard, you can can click on the link under default domain to test your app.?

Deployment?

  • Leveraging a Pre-built Example: To streamline the process, we’ll utilize a readily available Python example provided by Microsoft. Here’s the link to the repository: AzureFlaskWebApp. This repository contains a basic Flask application. It serves as a perfect starting point for understanding the deployment process.

  • Understanding the Code: (Optional) While not essential for deployment, taking a moment to explore the code within the repository can be beneficial. This example uses Flask, a popular microframework for building web applications in Python. The app.py file contains the core logic of the application. The requirements.txt file lists the necessary Python packages required for the application to function.
  • Connecting to Azure App Service: Navigate back to your newly created App Service resource in the Azure portal. Within the App Service blade, locate the Deployment Center section. This is where you’ll configure and initiate the deployment of your application code.
  • Choosing a Source: Since we’re using a publicly available GitHub repository, select GitHub as the source for your deployment.

  • Authorising Your Account: Click on Authorise to connect your Azure App Service to your GitHub account. This grants Azure App Service the necessary permissions to access and deploy your code from the chosen repository. You might encounter an authorisation issue here if you’re using a two-factor authentication (2FA) enabled account. In such cases, you might need to create a separate GitHub account specifically for deployment purposes, or utilize alternative authentication methods provided by Azure, like personal access tokens.
  • Selecting the Repository: Once authorised, a list of your GitHub repositories will be displayed. Choose the forked repository containing the Python example code (e.g., azure-samples/python-docs-hello-world) that you created earlier.
  • Branch Selection: By default, the main branch will likely be selected for deployment. This is the recommended branch for production deployments. Azure App Service can deploy code from any branch within your repository, allowing you to test and stage changes before pushing them to production.

  • Initiating Deployment: After reviewing the configuration details, click Next to proceed. On the subsequent screen, you’ll have the option to configure additional deployment settings (these are optional for this basic example). Once you’re ready, click Save to initiate the deployment process.
  • Deployment Progress: Azure App Service will take your code from the chosen GitHub repository and deploy it to your App Service. This process typically takes a few minutes to complete. You can monitor the progress within the Deployment Center.

Accessing Your Deployed Application

Once the deployment is complete, you’re ready to access your Python web application running live on Azure!

  • Locating the URL: In the App Service overview blade, locate the URL under the Overview section. This URL represents the public endpoint where users can access your application.

  • Opening the Application: Copy the URL and paste it into your web browser. You should be greeted by “Welcome to Azure” message displayed by your deployed Python application. Congratulations! You’ve successfully deployed your first web application to Azure App Service.

This walkthrough has provided a detailed explanation of deploying a Python web application to Azure App Service. By following these steps, you’ve gained valuable experience in leveraging the power and convenience of Azure for your Python application deployments. As you delve deeper into Azure App Service, you can explore more advanced functionalities like deployment slots, continuous integration/continuous delivery (CI/CD) pipelines, and scaling your application to meet growing demands.

要查看或添加评论,请登录

社区洞察

其他会员也浏览了