This is a simple example on how to expose Azure Map API with Azure Function in Python.
When creating Function App, please have the followings
- Runtime stack = Python
- Version=3.8 (or a version that matches your Python version)
and add an Application Setting under Configuration Section
SUBSCRIPTION_ID=<the primary/secondary key of Azure map>
git clone https://github.com/dennisseah/azure-fn-map.git
you use python
(instead of python3
) if you are not on mac-osx
cd azure-fn-map.git
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
pip3 install -r requirements-dev.txt
open vscode on the current git folder
code .
create a file, local.settings.json
. The content of this file is
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "python",
"SUBSCRIPTION_ID": "<the primary/secondary key of Azure map>"
}
}
I have my .vscode/launch.json
like this
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Python Functions",
"type": "python",
"request": "attach",
"port": 9091,
"preLaunchTask": "func: host start"
}
]
}
I have my .vscode/settings.json
like this
{
"python.pythonPath": "venv/bin/python",
"azureFunctions.deploySubpath": ".",
"azureFunctions.scmDoBuildDuringDeployment": true,
"azureFunctions.pythonVenv": "venv",
"azureFunctions.projectLanguage": "Python",
"azureFunctions.projectRuntime": "~3",
"debug.internalConsoleOptions": "neverOpen"
}
I have my .vscode/extensions.json
like this
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-python.python"
]
}
Click on the Run Icon on the Left Icon Panel, and then click on the Attach to Python Functions option. Once the debugger is up, you can point your browser to
http://localhost:7071/api/AddressSearch
http://localhost:7071/api/ReverseGeo
Click on the Azure Icon on the Left Icon Panel, and then click Deploy to Function App icon. Select the subscription and function app accordingly. Once the deployment is done, you can point your browser to
http://<function-app-host>/api/AddressSearch
http://<function-app-host>/api/ReverseGeo