Create an Azure CDN profile and endpoint using the Azure CLI
As an alternative to the Azure portal, you can use these sample Azure CLI scripts to manage the following CDN operations:
- Create a CDN profile.
- Create a CDN endpoint.
- Create a CDN origin group and make it the default group.
- Create a CDN origin.
- Create a custom domain and enable HTTPS.
Prerequisites
Use the Bash environment in Azure Cloud Shell. For more information, see Quickstart for Bash in Azure Cloud Shell.
If you prefer to run CLI reference commands locally, install the Azure CLI. If you're running on Windows or macOS, consider running Azure CLI in a Docker container. For more information, see How to run the Azure CLI in a Docker container.
If you're using a local installation, sign in to the Azure CLI by using the az login command. To finish the authentication process, follow the steps displayed in your terminal. For other sign-in options, see Sign in with the Azure CLI.
When you're prompted, install the Azure CLI extension on first use. For more information about extensions, see Use extensions with the Azure CLI.
Run az version to find the version and dependent libraries that are installed. To upgrade to the latest version, run az upgrade.
Sample scripts
If you don't already have a resource group for your CDN profile, create it with the command az group create
:
# Create a resource group to use for the CDN.
az group create --name MyResourceGroup --location eastus
The following Azure CLI script creates a CDN profile and CDN endpoint:
# Create a CDN profile.
az cdn profile create --resource-group MyResourceGroup --name MyCDNProfile --sku Standard_Microsoft
# Create a CDN endpoint.
az cdn endpoint create --resource-group MyResourceGroup --name MyCDNEndpoint --profile-name MyCDNProfile --origin www.contoso.com
The following Azure CLI script creates a CDN origin group, sets the default origin group for an endpoint, and creates a new origin:
# Create an origin group.
az cdn origin-group create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyOriginGroup --origins origin-0
# Make the origin group the default group of an endpoint.
az cdn endpoint update --resource-group MyResourceGroup --name MyCDNEndpoint --profile-name MyCDNProfile --default-origin-group MyOriginGroup
# Create another origin for an endpoint.
az cdn origin create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name origin-1 --host-name example.contoso.com
The following Azure CLI script creates a CDN custom domain and enables HTTPS. Before you can associate a custom domain with an Azure CDN endpoint, you must first create a canonical name (CNAME) record with Azure DNS or your DNS provider to point to your CDN endpoint. For more information, see Create a CNAME DNS record.
# Associate a custom domain with an endpoint.
az cdn custom-domain create --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyCustomDomain --hostname www.example.com
# Enable HTTPS on the custom domain.
az cdn custom-domain enable-https --resource-group MyResourceGroup --endpoint-name MyCDNEndpoint --profile-name MyCDNProfile --name MyCustomDomain
Clean up resources
After you've finished running the sample scripts, use the following command to remove the resource group and all resources associated with it.
# Delete the resource group.
az group delete --name MyResourceGroup
Azure CLI commands used in this article
Feedback
Submit and view feedback for