|
| 1 | +--- |
| 2 | +title: 'Tutorial: Python connect to Azure services securely with Key Vault' |
| 3 | +description: Learn how to secure connectivity to back-end Azure services that don't support managed identity natively from a Python web app |
| 4 | +ms.devlang: python |
| 5 | +# ms.devlang: python, azurecli |
| 6 | +ms.topic: tutorial |
| 7 | +ms.date: 08/23/2024 |
| 8 | +author: cephalin |
| 9 | +ms.author: cephalin |
| 10 | + |
| 11 | +ms.reviewer: madsd |
| 12 | +ms.custom: devx-track-azurecli, devx-track-python, AppServiceConnectivity |
| 13 | +--- |
| 14 | + |
| 15 | +# Tutorial: Secure Cognitive Service connection from Python App Service using Key Vault |
| 16 | + |
| 17 | +[!INCLUDE [tutorial-content-above-code](./includes/tutorial-connect-msi-key-vault/introduction.md)] |
| 18 | + |
| 19 | +## Configure Python app |
| 20 | + |
| 21 | +Clone the sample repository locally and deploy the sample application to App Service. Replace *\<app-name>* with a unique name. |
| 22 | + |
| 23 | +```azurecli-interactive |
| 24 | +# Clone and prepare sample application |
| 25 | +git clone https://github.com/Azure-Samples/app-service-language-detector.git |
| 26 | +cd app-service-language-detector/python |
| 27 | +zip -r default.zip . |
| 28 | +
|
| 29 | +# Save app name as variable for convenience |
| 30 | +appName=<app-name> |
| 31 | +
|
| 32 | +az appservice plan create --resource-group $groupName --name $appName --sku FREE --location $region --is-linux |
| 33 | +az webapp create --resource-group $groupName --plan $appName --name $appName --runtime "python:3.11" |
| 34 | +az webapp config appsettings set --resource-group $groupName --name $appName --settings SCM_DO_BUILD_DURING_DEPLOYMENT=true |
| 35 | +az webapp deploy --resource-group $groupName --name $appName --src-path ./default.zip |
| 36 | +``` |
| 37 | + |
| 38 | +The preceding commands: |
| 39 | + |
| 40 | +* Create a linux app service plan |
| 41 | +* Create a web app for Python 3.11 |
| 42 | +* Configure the web app to install the python packages on deployment |
| 43 | +* Upload the zip file, and install the python packages |
| 44 | + |
| 45 | +## Configure secrets as app settings |
| 46 | + |
| 47 | +[!INCLUDE [tutorial-content-below-code](./includes/tutorial-connect-msi-key-vault/cleanup.md)] |
0 commit comments