Deploy Functions to Azure
After creating a local Azure Functions environment and local Functions project on Mac(M1), I create Azure resources and deploy the Functions.
Environment settings
- MacOS Monterey 12.3, M1 Apple silicon
- Rosetta 2
1 2
% uname -a Darwin xxx 21.4.0 Darwin Kernel Version 21.4.0: Mon Feb 21 20:35:58 PST 2022; root:xnu-8020.101.4~2/RELEASE_ARM64_T6000 x86_64
- pyenv 2.3.18
- Python 3.10.0
- Homebrew 4.0.20
- azure-functions-core-tools@4/4.0.5198
Create a local Azure Functions project
create-local-azure-functions-project
Install Azure cli
Azure CLI requires python3.10. After checking python as 3.10, install over brew.
|
|
Check cli ersion.
|
|
Login
|
|
If you cannot complete login, you may assign Azure role to your account resource group.
Add Azure role for the resource
Ref. : Assign Azure roles using the Azure portal
At portal.azure.com
, open the Add role assignment page.
- Click Access Control
- Click the Role assignments tab to view the role assignments at this scope.
- Click Add > Add role assignment.
- Select “Privileged administrator roles”
- In the Details column, click View to get more details about a role.
- Select who needs access
After assigning role, you can login successfully.
|
|
Create resource group
Create a resource group “AzureFunctionsQuickstart-rg” on location “Japan East”.
|
|
Create storage account
Create generic storage accounts “azstrorage01” within resource groups and regions.
|
|
Create Functions in Azure
Check functionapp consumption location
|
|
Create Functions
- Resource group: AzureFunctionsQuickstart-rg
- consumption location: japaneast
- Python runtime-version: 3.9
- functions-version: 4
- name: FunctionProjDemo
- storage-account: azstrorage01
|
|
Once you create the Functions app successfully, you will see the Functions App and Application insight at the Azure portal.
Deploying a Function Project to Azure
Once you have successfully created a function app to Azure, you can deploy your local function project using the func azure functionapp publish command.
Check the remote project name:
|
|
Run the below command using func
on Rosetta terminal in my case. At the local project directory (in my case, the directory name is FunctionProjDemo
),
|
|
To use the Python v2 model in your function app, you must add the value EnableWorkerIndexing to your new application configuration in Azure with the name AzureWebJobsFeatureFlags.
|
|
Then you will see the configured endpoint to be invoked.
|
|
Using Function keys
The Invoke URL above still returns 401
Unauthorization error.
Below list the function keys
|
|
Or you can check the same on Azure portal - All resources > (your function) > App key.
For accessing with key, you need specify it by “code” request parameter.
https://functionprojdemohlb.azurewebsites.net/api/hello?code="your function key"
Or you can set it by x-functions-key
header.
Then finally, you can get response from deployed function on Azure.
Furthermore, you can use decorator function parameter(@app.route.auth_level) and configure authlevel. If Authlevel is ANONYMOUS, client does not need to use function keys for accessing to the function.
|
|
Confirmation on Application Insight
Azure portal’s Application Insights displays real-time streaming logs
|
|