Options for running Python scripts in Azure
I have a Python script that gets data from Google Analytics and puts in into a CSV file. I currently run this script on a local machine but I'd like to run the script in my companies Azure tenant. What Azure service could / should I use to run this script on a daily schedule?
Solution 1:
For your needs, I suggest you use Web Jobs in Web Apps Service.
It has two types of Azure Web Jobs for you to choose: Continuous and Trigger. For your needs, Trigger should be adopted.
You could refer to the document here for more details.In addition, here shows how to run tasks in WebJobs.
I created a simple Trigger webjob for your reference.
Step 1: I write a Sample.py as below:
I used the python third-party module virtualenv create a isolated python environment and used the pip install requests
command line to download the libs packages that the requests depend on.
then keep the Sample.py uniformly compressed into a folder with the libs packages dependent on the requests that you rely on.
Step 2: Create webjob in Web app service. Here, I choose Triggered Type and set cron expression 0/5 * * * * *
which means this job will be excuted per 5 seconds.
you'll see the Web Job list after your successful creation.
Step 3: You could check your running web job's status and logs via the Logs button as below:
Solution 2:
In addition to the first answer you can also use azure functions with a timer which is basically a script on a cronjob without a full machine and paid by invocation. https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview