You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/service-connector/tutorial-django-webapp-postgres-cli.md
+5-149Lines changed: 5 additions & 149 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,36 +7,17 @@ author: maud-lv
7
7
ms.author: malev
8
8
ms.service: service-connector
9
9
ms.topic: tutorial
10
-
ms.date: 11/22/2023
11
-
zone_pivot_groups: postgres-server-options
10
+
ms.date: 05/13/2024
12
11
---
13
12
# Tutorial: Using Service Connector to build a Django app with Postgres on Azure App Service
14
13
15
14
> [!NOTE]
16
-
> You are using Service Connector that makes it easier to connect your web app to database service in this tutorial. The tutorial here is a modification of the [App Service tutorial](../app-service/tutorial-python-postgresql-app.md) to use this feature so you will see similarities. Look into section [Configure environment variables to connect the database](#configure-environment-variables-to-connect-the-database) in this tutorial to see where Service Connector comes into play and simplifies the connection process given in the App Service tutorial.
15
+
> In this tutorial, you use Service Connector that simplifies the process of connecting a web app to a database service. This tutorial is a modification of the [App Service tutorial](../app-service/tutorial-python-postgresql-app.md), so you may see some similarities. Look into section [Configure environment variables to connect the database](#configure-environment-variables-to-connect-the-database) to see where Service Connector comes into play and simplifies the connection process given in the App Service tutorial.
17
16
18
-
::: zone pivot="postgres-single-server"
19
-
20
-
This tutorial shows how to deploy a data-driven Python [Django](https://www.djangoproject.com/) web app to [Azure App Service](overview.md) and connect it to an Azure Database for a Postgres database. You can also try the PostgreSQL Flexible Server by selecting the option above. Flexible Server provides a simpler deployment mechanism and lower ongoing costs.
17
+
This tutorial shows how to deploy a data-driven Python [Django](https://www.djangoproject.com/) web app to [Azure App Service](overview.md) and connect it to an [Azure Database for PostgreSQL Flexible server](../postgresql/flexible-server/index.yml) database.
21
18
22
19
In this tutorial, you use the Azure CLI to complete the following tasks:
23
20
24
-
> [!div class="checklist"]
25
-
> * Set up your initial environment with Python and the Azure CLI
26
-
> * Create an Azure Database for PostgreSQL database
27
-
> * Deploy code to Azure App Service and connect to PostgreSQL
28
-
> * Update your code and redeploy
29
-
> * View diagnostic logs
30
-
> * Manage the web app in the Azure portal
31
-
32
-
:::zone-end
33
-
34
-
::: zone pivot="postgres-flexible-server"
35
-
36
-
This tutorial shows how to deploy a data-driven Python [Django](https://www.djangoproject.com/) web app to [Azure App Service](overview.md) and connect it to an [Azure Database for PostgreSQL Flexible server](../postgresql/flexible-server/index.yml) database. If you can't use PostgreSQL Flexible server, then select the Single Server option above.
37
-
38
-
In this tutorial, you'll use the Azure CLI to complete the following tasks:
39
-
40
21
> [!div class="checklist"]
41
22
> * Set up your initial environment with Python and the Azure CLI
42
23
> * Create an Azure Database for PostgreSQL Flexible server database
@@ -45,12 +26,6 @@ In this tutorial, you'll use the Azure CLI to complete the following tasks:
45
26
> * View diagnostic logs
46
27
> * Manage the web app in the Azure portal
47
28
48
-
:::zone-end
49
-
50
-
## Prerequisites
51
-
52
-
* An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/).
53
-
54
29
## Set up your initial environment
55
30
56
31
1. Install [Python 3.8 or higher](https://www.python.org/downloads/). To check if your Python version is 3.8 or higher, run the following code in a terminal window:
@@ -95,26 +70,18 @@ Navigate into the following folder:
95
70
cd serviceconnector-webapp-postgresql-django
96
71
```
97
72
98
-
::: zone pivot="postgres-flexible-server"
99
-
100
73
Use the flexible-server branch of the sample, which contains a few necessary changes, such as how the database server URL is set and adding `'OPTIONS': {'sslmode': 'require'}` to the Django database configuration as required by Azure PostgreSQL Flexible server.
For Flexible server, selectthe branches control that says "master" and thenselectthe**flexible-server** branch.
115
84
116
-
::: zone-end
117
-
118
85
Select **Code**, and thenselect**Download ZIP**.
119
86
120
87
Unpack the ZIP file into a folder named *djangoapp*.
@@ -136,64 +103,6 @@ Having issues? [Let us know](https://aka.ms/DjangoCLITutorialHelp).
136
103
137
104
## Create Postgres database in Azure
138
105
139
-
::: zone pivot="postgres-single-server"
140
-
141
-
<!-- > [!NOTE]
142
-
> Before you create an Azure Database for PostgreSQL server, check which [compute generation](../postgresql/concepts-pricing-tiers.md#compute-generations-and-vcores) is available in your region. -->
143
-
144
-
1. Enable parameters caching with the Azure CLI so you don't need to provide those parameters with every command. (Cached values are saved in the *.azure* folder.)
145
-
146
-
```azurecli
147
-
az config param-persist on
148
-
```
149
-
150
-
1. Install the `db-up` extension for the Azure CLI:
151
-
152
-
```azurecli
153
-
az extension add --name db-up
154
-
```
155
-
156
-
If the `az`command isn't recognized, be sure you have the Azure CLI installed as described in [Set up your initial environment](#set-up-your-initial-environment).
157
-
158
-
1. Create the Postgres database in Azure with the [`az postgres up`](/cli/azure/postgres#az-postgres-up) command:
159
-
160
-
```azurecli
161
-
az postgres up --resource-group ServiceConnector-tutorial-rg --location eastus --sku-name B_Gen5_1 --server-name <postgres-server-name> --database-name pollsdb --admin-user <admin-username> --admin-password <admin-password> --ssl-enforcement Enabled
162
-
```
163
-
164
-
Replace the following placeholder texts with your own data:
165
-
166
-
* **Replace** *`<postgres-server-name>`* with a name that's **unique across all Azure** (the server endpoint becomes `https://<postgres-server-name>.postgres.database.azure.com`). A good pattern is to use a combination of your company name and another unique value.
167
-
168
-
* For *`<admin-username>`* and *`<admin-password>`*, specify credentials to create an administrator user for this Postgres server. The admin username can't be *azure_superuser*, *azure_pg_admin*, *admin*, *administrator*, *root*, *guest*, or *public*. It can't start with *pg_*. The password must contain **8 to 128 characters** from three of the following categories: English uppercase letters, English lowercase letters, numbers (0 through 9), and non-alphanumeric characters (for example, *!*, *#*, *%*). The password can't contain a username.
169
-
* Don't use the `$` character in the username or password. You'll later create environment variables with these values where the `$` character has special meaning within the Linux container used to run Python apps.
170
-
* The `*B_Gen5_1*` (Basic, Gen5, 1 core) [pricing tier](../postgresql/concepts-pricing-tiers.md) used here is the least expensive. For production databases, omit the `--sku-name` argument to use the GP_Gen5_2 (General Purpose, Gen 5, 2 cores) tier instead.
171
-
172
-
This command performs the following actions, which may take a few minutes:
173
-
174
-
* Create a [resource group](../azure-resource-manager/management/overview.md#terminology) called `ServiceConnector-tutorial-rg`, if it doesn't already exist.
175
-
* Create a Postgres server named by the `--server-name` argument.
176
-
* Create an administrator account using the `--admin-user` and `--admin-password` arguments. You can omit these arguments to allow the command to generate unique credentials for you.
177
-
* Create a `pollsdb` database as named by the `--database-name` argument.
178
-
* Enable access from your local IP address.
179
-
* Enable access from Azure services.
180
-
* Create a database user with access to the `pollsdb` database.
181
-
182
-
You can do all the steps separately with other `az postgres` and `psql` commands, but `az postgres up` does all the steps together.
183
-
184
-
When the command completes, it outputs a JSON object that contains different connection strings for the database along with the server URL, a generated user name (such as "joyfulKoala@msdocs-djangodb-12345"), and a GUID password.
185
-
186
-
> [!IMPORTANT]
187
-
> Copy the user name and password to a temporary text file as you will need them later in this tutorial.
188
-
189
-
<!-- not all locations support az postgres up -->
190
-
> [!TIP]
191
-
> `-l <location-name>` can be set to any [Azure regions](https://azure.microsoft.com/global-infrastructure/regions/). You can get the regions available to your subscription with the [`az account list-locations`](/cli/azure/account#az-account-list-locations) command. For production apps, put your database and your app in the same location.
192
-
193
-
::: zone-end
194
-
195
-
::: zone pivot="postgres-flexible-server"
196
-
197
106
1. Enable parameters caching with the Azure CLI so you don't need to provide those parameters with every command. (Cached values are saved in the *.azure* folder.)
198
107
199
108
```azurecli
@@ -227,8 +136,6 @@ Having issues? [Let us know](https://aka.ms/DjangoCLITutorialHelp).
227
136
228
137
1. When the command completes, **copy the command's JSON output to a file** as you need values from the output later in this tutorial, specifically the host, username, and password, along with the database name.
229
138
230
-
::: zone-end
231
-
232
139
Having issues? [Let us know](https://aka.ms/DjangoCLITutorialHelp).
233
140
234
141
## Deploy the code to Azure App Service
@@ -237,36 +144,6 @@ In this section, you create app host in App Service app, connect this app to the
237
144
238
145
### Create the App Service app
239
146
240
-
::: zone pivot="postgres-single-server"
241
-
242
-
1. In the terminal, make sure you're in the *djangoapp* repository folder that contains the app code.
243
-
244
-
1. Create an App Service app (the host process) with the [`az webapp up`](/cli/azure/webapp#az-webapp-up) command:
245
-
246
-
```azurecli
247
-
az webapp up --resource-group ServiceConnector-tutorial-rg --location eastus --plan ServiceConnector-tutorial-plan --sku B1 --name <app-name>
248
-
```
249
-
<!-- without --sku creates PremiumV2 plan -->
250
-
251
-
* For the `--location` argument, make sure you use the location that [Service Connector supports](concept-region-support.md).
252
-
***Replace***\<app-name>* with a unique name across all Azure (the server endpoint is `https://<app-name>.azurewebsites.net`). Allowed characters for*\<app-name>* are `A`-`Z`, `0`-`9`, and `-`. A good pattern is to use a combination of your company name and an app identifier.
253
-
254
-
This command performs the following actions, which may take a few minutes:
255
-
256
-
<!-- - Create the resource group if it doesn't exist. `--resource-group` is optional. -->
257
-
<!-- No it doesn't. az webapp up doesn't respect --resource-group -->
258
-
259
-
* Create the [resource group](../azure-resource-manager/management/overview.md#terminology) if it doesn't already exist. (In this command you use the same resource group in which you created the database earlier.)
260
-
* Create the [App Service plan](../app-service/overview-hosting-plans.md) *DjangoPostgres-tutorial-plan*in the Basic pricing tier (B1), if it doesn't exist. `--plan` and `--sku` are optional.
261
-
* Create the App Service app if it doesn't exist.
262
-
* Enable default logging for the app, if not already enabled.
263
-
* Upload the repository using ZIP deployment with build automation enabled.
264
-
* Cache common parameters, such as the name of the resource group and App Service plan, into the file *.azure/config*. As a result, you don't need to specify all the same parameter with later commands. For example, to redeploy the app after making changes, you can just run `az webapp up` again without any parameters. Commands that come from CLI extensions, such as `az postgres up`, however, do not at present use the cache, which is why you needed to specify the resource group and location here with the initial use of `az webapp up`.
265
-
266
-
::: zone-end
267
-
268
-
::: zone pivot="postgres-flexible-server"
269
-
270
147
1. In the terminal, make sure you're in the *djangoapp* repository folder that contains the app code.
271
148
272
149
1. Switch to the sample app's `flexible-server` branch. This branch contains specific configuration needed for PostgreSQL Flexible server:
@@ -291,8 +168,6 @@ In this section, you create app host in App Service app, connect this app to the
291
168
* Enable default logging for the app.
292
169
* Upload the repository using ZIP deployment with build automation enabled.
293
170
294
-
::: zone-end
295
-
296
171
Upon successful deployment, the command generates JSON output like the following example:
297
172
298
173
:::image type="content" source="../app-service/media/tutorial-python-postgresql-app/az-webapp-up-output.png" alt-text="Screenshot of the terminal, showing an example output for the az webapp up command." :::
@@ -307,21 +182,6 @@ The app code expects to find database information in four environment variables
307
182
308
183
To set environment variables in App Service, create "app settings" with the following `az connection create` command.
309
184
310
-
::: zone pivot="postgres-single-server"
311
-
312
-
```azurecli
313
-
az webapp connection create postgres --client-type django
314
-
```
315
-
316
-
The resource group, app name, db name are drawn from the cached values. You need to provide admin password of your postgres database during the execution of this command.
317
-
318
-
* The command creates settings named "AZURE_POSTGRESQL_HOST", "AZURE_POSTGRESQL_NAME", "AZURE_POSTGRESQL_USER", "AZURE_POSTGRESQL_PASS" as expected by the app code.
319
-
* If you forgot your admin credentials, the command would guide you to reset it.
320
-
321
-
::: zone-end
322
-
323
-
::: zone pivot="postgres-flexible-server"
324
-
325
185
```azurecli
326
186
az webapp connection create postgres-flexible --client-type django
327
187
```
@@ -331,8 +191,6 @@ The resource group, app name, db name are drawn from the cached values. You need
331
191
* The command creates settings named "AZURE_POSTGRESQL_HOST", "AZURE_POSTGRESQL_NAME", "AZURE_POSTGRESQL_USER", "AZURE_POSTGRESQL_PASS" as expected by the app code.
332
192
* If you forgot your admin credentials, the command would guide you to reset it.
333
193
334
-
::: zone-end
335
-
336
194
> [!NOTE]
337
195
> If you see the error message "The subscription is not registered to use Microsoft.ServiceLinker", please run `az provider register -n Microsoft.ServiceLinker` to register the Service Connector resource provider and run the connection command again.
338
196
@@ -391,7 +249,7 @@ Having issues? Refer first to the [Troubleshooting guide](../app-service/configu
391
249
392
250
## Clean up resources
393
251
394
-
If you'd like to keep the app or continue to additional tutorials, skip ahead to [Next steps](#next-steps). Otherwise, to avoid incurring ongoing charges, delete the resource group created for this tutorial:
252
+
If you'd like to keep the app or continue to more tutorials, skip ahead to [Next steps](#next-step). Otherwise, to avoid incurring ongoing charges, delete the resource group created for this tutorial:
395
253
396
254
```azurecli
397
255
az group delete --name ServiceConnector-tutorial-rg --no-wait
@@ -403,9 +261,7 @@ Deleting all the resources can take some time. The `--no-wait` argument allows t
403
261
404
262
Having issues? [Let us know](https://aka.ms/DjangoCLITutorialHelp).
405
263
406
-
## Next steps
407
-
408
-
Follow the tutorials listed below to learn more about Service Connector.
264
+
## Next step
409
265
410
266
> [!div class="nextstepaction"]
411
267
> [Learn about Service Connector concepts](./concept-service-connector-internals.md)
Copy file name to clipboardExpand all lines: articles/service-connector/tutorial-java-spring-confluent-kafka.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ Create an instance of Azure Spring Apps by following [the Azure Spring Apps quic
98
98
1. Create the app with a public endpoint assigned. If you selected Java version 11 when generating the Spring Cloud project, include the `--runtime-version=Java_11` switch.
0 commit comments