When using Azure Machine Learning(AML) Service, there are cases where it is necessary to operate the pipeline under various business scenario. This sample demonstrates a scenario where users without access to AML can trigger an AML pipeline using an azure function.
What does this sample demonstrate:
- How to invoke AML pipeline using Azure Function
What doesn't this sample demonstrate:
- Azure Machine Learning Service Creation.
This repo contains sample code to trigger Azure ML pipelines from Azure Functions.
The folders are structured as following -
common
└── pipeline_trigger
├── devops_pipelines # Azure DevOps CI/CD pipeline definition
├── environment_setup # Azure DevOps IaC pipeline definition to provision Azure resources
├── media # images for README
│
├── src
│ ├── PipelineHttpTrigger # scripts for pipeline trigger
│ ├── .funcignore
│ ├── host.json
│ ├── local.settings.json.example
│ └── requirements.txt
│
├── tests
│ └── src
│ └── PipelineHttpTrigger
│ └── test_pipeline_http_trigger.py # unit test for pipeline trigger
│
├── .flake8 # configuration file for linter flake8
├── .gitattributes
├── .gitignore
└── README.md # explains what the sample is demonstrating and how to run it
This 'pipeline_trigger' folder contains source code for an Azure Function below:
Function | Purpose |
---|---|
PipelineHttpTrigger | HTTP trigger - This function will be triggered to run the AML pipeline when manually HTTP request including key is sent. |
- 1. Create Azure Resources
- 2. Set AML access right to Azure Function
- 3. Option 1: Deploy the function project to Azure - Local
- 3. Option 2: Deploy the function project to Azure - CI/CD in Azure DevOps
- 4. How to use pipeline trigger
- How to renew a key
- Linting and Testing
Please refer to this README.md under environment_setup/provisioning
-
Install Azure CLI version 2.4 or later. Make sure to check the version by running
az --version
. -
Python 3.8 (64-bit), Python 3.7 (64-bit), Python 3.6 (64-bit), which are all supported by version 3.x of Azure Functions. Make sure by running
python --version
(Linux/macOS) orpy --version
(Windows) to check your Python version reports 3.8.x, 3.7.x or 3.6.x. -
Install pip packages using reqirements.txt in
src
folder.$ pip install -r requirements.txt
-
Login to Azure:
$ az login
-
Check which subscription you are currently using:
$ az account show -o table
If you are not in the subscription you want to use, use 'az account set -s [subscription id]' to switch. You can use 'az account list' to get all the subscription id.
-
Deploy your local functions project by using the
func azure functionapp publish
command. Replace <APP_NAME> with the name of your app.$ func azure functionapp publish <APP_NAME>
This sample contains Azure DevOps pipeline yaml files in devops_pipelines folder. To use Azure DevOps pipeline, follow the steps below.
- Update values for variables-template.yml.
- Create Azure pipeline by using trigger-functions-ci.yml and run it.
- Go to Function App
func-trigger-(BASE_NAME)
- Click
Functions
and selectPipelineHttpTrigger
- Click
Code + Test
and then clickGet function URL
- Copy URL which is including a key
- Past the URL to Postman and send it
Please follow the steps below when you want to renew a key.
- Go to Function App
func-trigger-(BASE_NAME)
- Click
Functions
and selectPipelineHttpTrigger
- Click
Function Keys
- Click
Renew key value
of default
This sample uses Flake8 as linting tool. See .flake8 for rule settings.
This sample uses pytest for unit testing python code. test_pipeline_http_trigger.py demonstrate how to mock Azure Function Python SDK and write unit test code.