- author: Dave Ebbelaar
Deploying AI Apps to the Cloud: A Step-by-Step Guide
If you are running a business, working for a client or within a company, deploying AI apps to the cloud is an essential step towards offering a complete and accessible solution to users. While setting up an AI app on a local device may be easy, deploying it to a server where users can access it can be tricky. Fortunately, in this article, we'll be showing you the step-by-step process of deploying an AI app to the cloud, specifically in Microsoft Azure. However, keep in mind that you can use this guide with any cloud platform such as AWS or the Google Cloud platform.
Why is Deploying AI Apps to the Cloud Important?
Understanding how to deploy AI apps to the cloud is crucial to delivering end-to-end solutions. As a data scientist or software engineer, possessing this skill set will help you bridge the gap between these two domains. It means you can conceive an idea and see it to completion, enabling you to sell it as a product or service to potential clients.
Setting Up a New Azure Account
Before we can begin deploying AI apps to the cloud, you need to sign up for an Azure account. You can do this by going to Microsoft Azure's website and creating a new account. If you are new to Azure, you can get up to $200 credits for free to test out the platform. Once you have created an Azure account, you'll need to create a resource group.
Creating a Resource Group
A resource group in Azure is like a top-level directory where you can store all your resources and services related to your project. You can create a resource group by:
- Logging into your new Azure account.
- Clicking on "Resource groups" from the Azure dashboard.
- Clicking on the "+Add" icon to create a new resource group.
- Naming the resource group appropriately.
- Selecting the region closest to your location.
Once you have created the resource group, you can now begin adding resources to your project.
Creating an App Service
An app service is a managed platform that allows you to deploy, build and scale web applications conveniently on Azure. For our purposes, we need to create a web app server. Here's how to create an app service in Azure:
- Click on "Create a resource."
- Search for "app service" and select the "Web App" option.
- Enter a unique name for your new app service.
- Choose the appropriate Resource Group where you want to add the app service.
- Choose the appropriate runtime Python version.
- Select the appropriate region closest to your location.
- Create a pricing plan for your server.
Once you have created your app service, you can now begin deploying your AI app to the cloud.
Deploying Your AI App
To deploy your AI app, you'll need to follow these steps:
- Create a GitHub repository where you'll push your code changes.
- Clone the repository to your local machine where your AI app code is stored.
- Make the necessary code changes to ensure it can be deployed to your app service.
- Commit your changes to the local repository.
- Push the changes to the remote GitHub repository.
Once you have set up the repository, every time you push changes to the repository, Azure will automatically deploy the new version of your app to the app service.
Conclusion
As we've seen, deploying AI apps to the cloud requires a series of well-defined steps that anyone with the right skills can follow. In this guide, we've shown you how to create an Azure account, set up a resource group, create an app service, and deploy your AI app to the cloud. But this is just the beginning; there is much more to learn about the possibilities that the cloud offers. With practice, you'll quickly become an expert in deploying AI apps to the cloud, opening up a world of opportunities for your business or client.
Deploying an Azure Web App via GitHub
In this tutorial, we will walk you through the steps of deploying an Azure Web App via GitHub. We will cover how to connect and authorize your GitHub repository with Azure and create a workflow to enable automated deployments.
Understanding Azure Components
Before diving into the details of deploying through GitHub, it is essential to understand the basic components of Azure. Azure has app servers and app service plans that work together to host web applications. App service plans provide computing resources, while app servers run the web applications.
Deploying via GitHub
Deploying via GitHub is convenient because it allows you to make changes locally, commit them to GitHub, and trigger an action to redeploy the application on the web server. Here are the steps to initiate the deployment process:
- Go to the Azure Deployment Center within your web app.
- Select the source and choose GitHub.
- Clone the repository and push it to your GitHub account.
- Delete the entire ".GitHub" folder, which holds the workflow.
- Authorize your account and select your organization, repository, and branch.
- Create a workflow file, which will trigger the deployment after committing and pushing.
- Hit save and wait while Azure adds the ".GitHub" directory with the workflows to your repository.
- Pull everything into your project.
Updating the Startup Text File
To instruct Azure about what to do when starting the app, we create a startup.txt file in the root directory of your repository. It should contain the following command:
gunicornslack:flask_app-w3-b"0.0.0.0:8000"
Ensure that the file points to the Flask app with the correct path and directory name.
Updating the Azure Configuration
An essential step in deploying an Azure web app is updating the Azure configuration with keys and secrets. When working locally, use the ".env" file to store the application secrets, but when deployed on Azure, it is necessary to update the application settings manually.
To update the Azure configuration, follow these steps:
- Go to the Configuration tab and then General Settings.
- Update the startup command with "startup.txt."
- Go to Application Settings and add new settings for the secrets.
- Ensure that all keys are included as environment variables and stored securely.
Updating the Workflow File
Finally, we will update the GitHub Actions workflow file to enable automated deployments. We will log in using the Azure CLI and the service principle. Here are the steps:
- Update your workflow file with the code to log in via the Azure CLI.
- Create a service principle and replace your subscription ID with your actual subscription ID.
By following these steps, you can deploy an Azure web app seamlessly using GitHub.
Creating a Surface Principle and Updating Slack App Event Subscription
In this section, we will cover the final steps to deploy the Slackbot application to Azure.
Creating a Surface Principle
Firstly, we need to create a surface principle which is a security layer that protects our applications. To create it, we will take the following steps:
- Replace your subscription ID with your actual subscription ID in the code provided.
- Open the Azure Cloud shell by clicking on the shell icon and select the subscription and create a storage.
- Use Azure CLI command line interface to interact with our subscription using bash.
- Run the command copied previously, but update your subscription ID and the name for your service principle.
- Copy the whole Json response and keep it secure as this information should be private.
Once you have created the service principle, you need to store this information in a variable called Azure credentials in GitHub.
Updating Slack App Event Subscription
After we have added the service principle to the workflow and updated the secrets in GitHub, it's time to update the Python file. The changes we make include:
- Set the host to listen to all incoming connections and switch the port to 8000.
- Add the verification for enhanced security through two functions: verify slack request and require slack verification.
- Use a decorator to add requires slack verification to the Slack events.
Once we have updated the Python file, the final step is to update the Slack app event subscription.
We need to replace the ngrok URL with the real URL and endpoint of our application.
To complete this deployment, we commit and push the changes to GitHub, triggers the deployment action, and reference the Azure log stream for debugging.
Overall, these deployment steps may look complicated, but they are critical for adding an extra layer of security to the application.
Deploying an AI App to the Cloud using Python Flask and Azure
In this tutorial, we went over the step-by-step process of deploying an AI app to the cloud using Python Flask and Azure. We updated the Python file, deployed everything, and updated the Slack app event subscription.
To update the Slack app event subscription, follow the steps below:
- Check the default domain on your web app. The default domain will be the name of your app followed by ".azurewebsites.net".
- Copy the default domain and paste it into the Slack app event subscription.
- Add a new URL and include the endpoint (e.g. "/slack/events").
- Verify the URL and if it's correct, you should get a green check.
- Subscribe to both events and event names mentioned in the tutorial.
- Save the changes and test if everything is live.
If you followed all the steps, your Flask app should be running, and your Slack bot is listening to the updated event subscription URL. You can validate and test everything in Slack by messaging Emma and asking her questions.
Additionally, you can configure new functions for Emma, your personal assistant, to follow. We will explore this concept in detail in future videos. This is a valuable skill that can be used to implement end-to-end solutions for clients, teams, or as a product.
If you want to take your skills to the next level and find potential clients to work with, you should check out Data Freelancer, a Mastermind group of data professionals working on profit, fulfillment, and freedom through freelancing. We can help you set up a six-figure freelancing business in data.
Please don't forget to hit the like and subscribe button to support us and receive notifications for future content. Thank you for watching, and see you in the next one.