问题
Or reworded another way, can someone provide explanations for the different parameters for the az cdn endpoint rule add
command?
The Verizon documentation doesn't match up very well with the Azure CLI.
Verizon have moved from their v3 Rule Engine to v4, and while it is a massive improvement for layout and usability, it still doesn't provide information on what the specific fields are, or how they would map to the Azure CLI az cdn endpoint rule add
command.
One problem is that the new v4 interface has lost the "source" drop list with the internally created Verizon Id.
@Christopher Cabezudo Rodriguez has bruteforced how to get this value, but it doesn't help when trying to set this up using the CLI.
I have 3 HTTP Rules I want to create.
- The first HTTP rule allows our Angular Single Page Application “SPA” to work where navigation clicks that change the URL Address don’t reload or navigate away from the page.
- The second HTTP rule restricts HTTP traffic to route to HTTPS.
- The third HTTP rule tells the browser to always check to see if anything has changed between the CDN and the Cache. This will ensure that the user always downloads the latest version of the client application.
To Start with, I create the CDN and Endpoint like this:
az cdn profile create --name $AZ_APP_CDN --resource-group $AZ_RESOURCE_GROUP_APP --location $AZ_LOCATION --sku Premium_Verizon
az cdn endpoint create --name $AZ_APP_CDN_ENDPOINT --resource-group $AZ_RESOURCE_GROUP_APP --profile-name $AZ_APP_CDN --origin $ST_BLOB_ORIGIN_DOMAIN --no-http true
In the V4 Rules Engine they would look like this:
I've half-arsed together my best guess of what I might need as CLI commands to this:
az cdn endpoint rule add -g $AZ_RESOURCE_GROUP_APP -n $AZ_APP_CDN_ENDPOINT --profile-name $AZ_APP_CDN --order 0 --rule-name "Redirect" --match-variable RequestHeaderWildcard --match-variable "User-Agent" --operator Equal --match-values "ECPurge/*"--negate-condition true --action-name "UrlRewrite" --source-pattern "[^?.]*(\?.*)?$" --custom-fragment "client/index.html"
az cdn endpoint rule add -g $AZ_RESOURCE_GROUP_APP -n $AZ_APP_CDN_ENDPOINT --profile-name $AZ_APP_CDN --order 1 --rule-name "Http to Https" --match-variable RequestScheme --operator Equal --match-values HTTPS --action-name "UrlRedirect" --redirect-protocol Https --redirect-type Moved
az cdn endpoint rule add -g $AZ_RESOURCE_GROUP_APP -n $AZ_APP_CDN_ENDPOINT --profile-name $AZ_APP_CDN --order 2 --rule-name "Overwrite cache-control header" --match-variable Always --operator Equal --match-values HTTPS --action-name "ModifyClientResponseHeader" --header-action "Overwrite" --header-name "CacheControl" --header-value "max-age=0, must-revalidate, public"
Special mention that the second rule is actually given by the CLI help as an example, but it doesn't work. See:
az cdn endpoint rule add -h
For each of the above commands, I get the following 3 errors (numbered according to the rule):
- BadRequest - Name must be left blank for delivery rules in Verizon profiles
- validation error: Parameter 'DeliveryRuleAction.name' can not be None.
- az cdn endpoint rule add: error: the following arguments are required: --order, --rule-name, --action-name
Any help greatly appreciated ... I'll still keep banging my head against this wall and post if I work it out.
UPDATE: For not wanting to state the obvious, with Error #1 above, if I remove the --name
parameter (as the error suggests), I get the following error instead:
(--name | --ids) are required
UPDATE 2: The following Azure help page suggests az cdn endpoint rule action add
is correct, but it still doesn't work (provides cryptic error as per below).
The command failed with an unexpected error. Here is the traceback:
'NoneType' object has no attribute 'rules'
Traceback (most recent call last):
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\knack\knack\cli.py", line 215, in invoke
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\commands\__init__.py", line 631, in execute
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\commands\__init__.py", line 695, in _run_jobs_serially
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\commands\__init__.py", line 688, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\six\six.py", line 703, in reraise
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\commands\__init__.py", line 665, in _run_job
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\commands\__init__.py", line 324, in __call__
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli-core\azure\cli\core\__init__.py", line 574, in default_command_handler
File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-7cl6xofh\azure-cli\azure\cli\command_modules\cdn\custom.py", line 396, in add_action
AttributeError: 'NoneType' object has no attribute 'rules'
来源:https://stackoverflow.com/questions/62093666/what-is-the-correct-azure-cli-command-for-creating-http-rules-on-cdn-endpoints