Skip to content

Commit 633768b

Browse files
Merge pull request #178116 from jdmartinez36/afdclitutorial
Azure CLI Front Door end-to-end tutorial
2 parents 0d15b2d + df6022b commit 633768b

File tree

3 files changed

+572
-0
lines changed

3 files changed

+572
-0
lines changed

articles/frontdoor/standard-premium/TOC.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@
1313
items:
1414
- name: Create a Front Door Standard/Premium - Portal
1515
href: create-front-door-portal.md
16+
- name: Create a Front Door Standard/Premium - CLI
17+
href: create-front-door-cli.md
1618
- name: Samples
1719
items:
1820
- name: Resource Manager templates
1921
href: ../front-door-quickstart-template-samples.md?toc=%2fazure%2ffrontdoor%2fstandard-premium%2ftoc.json
2022
- name: Tutorials
2123
items:
24+
- name: Add delivery rules with the Azure CLI
25+
href: front-door-add-rules-cli.md
2226
- name: Configure security headers with Rules engine
2327
href: ../front-door-security-headers.md?toc=%2fazure%2ffrontdoor%2fstandard-premium%2ftoc.json
2428
- name: Concepts
Lines changed: 248 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
---
2+
title: Create an Azure Front Door Standard/Premium with the Azure CLI
3+
description: Learn how to create an Azure Front Door Standard/Premium (preview) with the Azure CLI. Use the Front Door to protect your web apps against vulnerabilities.
4+
ms.topic: sample
5+
author: duau
6+
ms.author: duau
7+
ms.service: frontdoor
8+
ms.date: 12/30/2021
9+
ms.custom: devx-track-azurecli
10+
11+
---
12+
13+
# Quickstart: Create an Azure Front Door Standard/Premium - Azure CLI
14+
15+
In this quickstart, you'll learn how to create an Azure Front Door Standard/Premium profile using the Azure CLI. You'll create this profile using two Web Apps as your origin, and add a WAF security policy. You can then verify connectivity to your Web Apps using the Azure Front Door Standard/Premium frontend hostname.
16+
17+
> [!NOTE]
18+
> This documentation is for Azure Front Door Standard/Premium (Preview). Looking for information on Azure Front Door? View [Azure Front Door Docs](../front-door-overview.md).
19+
20+
[!INCLUDE [quickstarts-free-trial-note](../../../includes/quickstarts-free-trial-note.md)]
21+
22+
[!INCLUDE [azure-cli-prepare-your-environment](../../../includes/azure-cli-prepare-your-environment.md)]
23+
24+
## Create a resource group
25+
26+
For this quickstart, you'll need two resource groups. One in *Central US* and the second in *East US*.
27+
28+
Run [az group create](/cli/azure/group#az_group_create) to create resource groups.
29+
30+
```azurecli
31+
az group create \
32+
--name myRGFDCentral \
33+
--location centralus
34+
35+
az group create \
36+
--name myRGFDEast \
37+
--location eastus
38+
```
39+
40+
## Create an Azure Front Door profile
41+
42+
Run [az afd profile create](/cli/azure/afd/profile#az_afd_profile_create) to create an Azure Front Door profile.
43+
44+
```azurecli
45+
az afd profile create \
46+
--profile-name contosoafd \
47+
--resource-group myRGFDCentral \
48+
--sku Premium_AzureFrontDoor \
49+
--subscription mysubscription
50+
```
51+
52+
## Create two instances of a web app
53+
54+
You need two instances of a web application that run in different Azure regions for this tutorial. Both the web application instances run in Active/Active mode, so either one can service traffic.
55+
56+
If you don't already have a web app, use the following script to set up two example web apps.
57+
58+
### Create app service plans
59+
60+
Before you can create the web apps you'll need two app service plans, one in *Central US* and the second in *East US*.
61+
62+
Run [az appservice plan create](/cli/azure/appservice/plan#az_appservice_plan_create&preserve-view=true) to create your app service plans.
63+
64+
```azurecli
65+
az appservice plan create \
66+
--name myAppServicePlanCentralUS \
67+
--resource-group myRGFDCentral
68+
69+
az appservice plan create \
70+
--name myAppServicePlanEastUS \
71+
--resource-group myRGFDEast
72+
```
73+
74+
### Create web apps
75+
76+
Run [az webapp create](/cli/azure/webapp#az_webapp_create&preserve-view=true) to create a web app in each of the app service plans in the previous step. Web app names have to be globally unique.
77+
78+
Run [az webapp list-runtimes](/cli/azure/webapp#az_webapp_create&preserve-view=true) to see a list of built-in stacks for web apps.
79+
80+
```azurecli
81+
az webapp create \
82+
--name WebAppContoso-001 \
83+
--resource-group myRGFDCentral \
84+
--plan myAppServicePlanCentralUS \
85+
--runtime "DOTNETCORE|2.1"
86+
87+
az webapp create \
88+
--name WebAppContoso-002 \
89+
--resource-group myRGFDEast \
90+
--plan myAppServicePlanEastUS \
91+
--runtime "DOTNETCORE|2.1"
92+
```
93+
94+
Make note of the default host name of each web app so you can define the backend addresses when you deploy the Front Door in the next step.
95+
96+
## Add an endpoint
97+
98+
Run [az afd endpoint create](/cli/azure/afd/endpoint#az_afd_endpoint_create) to create an endpoint in your profile. You can create multiple endpoints in your profile after finishing the create experience.
99+
100+
```azurecli
101+
az afd endpoint create \
102+
--resource-group myRGFDCentral \
103+
--endpoint-name contoso-frontend \
104+
--profile-name contosoafd \
105+
--origin-response-timeout-seconds 60 \
106+
--enabled-state Enabled
107+
```
108+
109+
## Create an origin group
110+
111+
Run [az afd origin-group create](/cli/azure/afd/origin-group#az_afd_origin_group_create) to create an origin group that contains your two web apps.
112+
113+
```azurecli
114+
az afd origin-group create \
115+
--resource-group myRGFDCentral \
116+
--origin-group-name og1 \
117+
--profile-name contosoafd \
118+
--probe-request-type GET \
119+
--probe-protocol Http \
120+
--probe-interval-in-seconds 120 \
121+
--probe-path /test1/azure.txt \
122+
--sample-size 4 \
123+
--successful-samples-required 3 \
124+
--additional-latency-in-milliseconds 50
125+
```
126+
127+
## Add an origin to the group
128+
129+
Run [az afd origin create](/cli/azure/afd/origin#az_afd_origin_create) to add an origin to your origin group.
130+
131+
```azurecli
132+
az afd origin create \
133+
--resource-group myRGFDCentral \
134+
--host-name webappcontoso-1.azurewebsites.net
135+
--profile-name contosoafd \
136+
--origin-group-name og1 \
137+
--origin-name contoso1 \
138+
--origin-host-header webappcontoso-1.azurewebsites.net \
139+
--priority 1 \
140+
--weight 1000 \
141+
--enabled-state Enabled \
142+
--http-port 80 \
143+
--https-port 443
144+
```
145+
146+
Repeat this step and add your second origin.
147+
148+
```azurecli
149+
az afd origin create \
150+
--resource-group myRGFDCentral \
151+
--host-name webappcontoso-2.azurewebsites.net
152+
--profile-name contosoafd \
153+
--origin-group-name og1 \
154+
--origin-name contoso2 \
155+
--origin-host-header webappcontoso-2.azurewebsites.net \
156+
--priority 1 \
157+
--weight 1000 \
158+
--enabled-state Enabled \
159+
--http-port 80 \
160+
--https-port 443
161+
```
162+
163+
## Add a route
164+
165+
Run [az afd route create](/cli/azure/afd/route#az_afd_route_create) to map your frontend endpoint to the origin group. This route forwards requests from the endpoint to *og1*.
166+
167+
```azurecli
168+
az afd route create \
169+
--resource-group myRGFDCentral \
170+
--endpoint-name contoso-frontend \
171+
--profile-name contosoafd \
172+
--route-name route1 \
173+
--https-redirect Enabled \
174+
--origin-group og1 \
175+
--supported-protocols Https \
176+
--link-to-default-domain Enabled \
177+
--forwarding-protocol MatchRequest
178+
```
179+
180+
## Create a new security policy
181+
182+
### Create a WAF policy
183+
184+
Run [az network front-door waf-policy create](/cli/azure/network/front-door/waf-policy#az_network_front_door_waf_policy_create) to create a WAF policy for one of your resource groups.
185+
186+
Create a new WAF policy for your Front Door. This example creates a policy that's enabled and in prevention mode.
187+
188+
```azurecli
189+
az network front-door waf-policy create
190+
--name contosoWAF /
191+
--resource-group myRGFDCentral /
192+
--sku Premium_AzureFrontDoor
193+
--disabled false /
194+
--mode Prevention
195+
```
196+
197+
> [!NOTE]
198+
> If you select `Detection` mode, your WAF doesn't block any requests.
199+
200+
### Create the security policy
201+
202+
Run [az afd security-policy create](/cli/azure/afd/security-policy#az_afd_security_policy_create) to apply your WAF policy to the endpoint's default domain.
203+
204+
```azurecli
205+
az afd security-policy create \
206+
--resource-group myRGFDCentral \
207+
--profile-name contosoafd \
208+
--security-policy-name contososecurity \
209+
--domains /subscriptions/mysubscription/resourcegroups/myRGFDCentral/providers/Microsoft.Cdn/profiles/contosoafd/afdEndpoints/contoso-frontend.z01.azurefd.net \
210+
--waf-policy /subscriptions/mysubscription/resourcegroups/myRGFDCentral/providers/Microsoft.Network/frontdoorwebapplicationfirewallpolicies/contosoWAF
211+
```
212+
213+
## Verify Azure Front Door
214+
215+
When you create the Azure Front Door Standard/Premium profile, it takes a few minutes for the configuration to be deployed globally. Once completed, you can access the frontend host you created. In a browser, go to `contoso-frontend.z01.azurefd.net`. Your request will automatically get routed to the nearest server from the specified servers in the origin group.
216+
217+
To test instant global failover, we'll use the following steps:
218+
219+
1. Open a browser, as described above, and go to the frontend address: `contoso-frontend.azurefd.net`.
220+
221+
2. In the Azure portal, search for and select *App services*. Scroll down to find one of your web apps, **WebAppContoso-1** in this example.
222+
223+
3. Select your web app, and then select **Stop**, and **Yes** to verify.
224+
225+
4. Refresh your browser. You should see the same information page.
226+
227+
>[!TIP]
228+
>There is a little bit of delay for these actions. You might need to refresh again.
229+
230+
5. Find the other web app, and stop it as well.
231+
232+
6. Refresh your browser. This time, you should see an error message.
233+
234+
:::image type="content" source="../media/create-front-door-portal/web-app-stopped-message.png" alt-text="Both instances of the web app stopped":::
235+
236+
## Clean up resources
237+
238+
When you don't need the resources for the Front Door, delete both resource groups. Deleting the resource groups also deletes the Front Door and all its related resources.
239+
240+
Run [az group delete](/cli/azure/group#az_group_delete&preserve-view=true):
241+
242+
```azurecli
243+
az group delete \
244+
--name myRGFDCentral
245+
246+
az group delete \
247+
--name myRGFDEast
248+
```

0 commit comments

Comments
 (0)