0
0
Azurecloud~5 mins

Azure CDN profiles and endpoints - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you want to deliver your website or app content faster to users worldwide, Azure CDN helps by storing copies of your content closer to them. Azure CDN profiles organize your CDN settings, and endpoints are the specific addresses where your content is delivered from.
When you want to speed up loading times for your website visitors around the world.
When you want to reduce the load on your main web server by caching content.
When you want to secure your content delivery with HTTPS and custom domains.
When you want to deliver large files like videos or software downloads efficiently.
When you want to improve user experience by reducing delays caused by distance.
Config File - azure-cdn-profile-endpoint.bicep
azure-cdn-profile-endpoint.bicep
param cdnProfileName string = 'exampleCdnProfile'
param cdnEndpointName string = 'exampleCdnEndpoint'
param resourceGroupName string = 'exampleResourceGroup'
param location string = 'eastus'
param originHostName string = 'www.example.com'

resource cdnProfile 'Microsoft.Cdn/profiles@2021-06-01' = {
  name: cdnProfileName
  location: location
  sku: {
    name: 'Standard_Microsoft'
  }
}

resource cdnEndpoint 'Microsoft.Cdn/profiles/endpoints@2021-06-01' = {
  name: '${cdnProfile.name}/${cdnEndpointName}'
  location: location
  properties: {
    origins: [
      {
        name: 'origin1'
        properties: {
          hostName: originHostName
        }
      }
    ]
    isHttpAllowed: true
    isHttpsAllowed: true
  }
  dependsOn: [cdnProfile]
}

This Bicep file creates an Azure CDN profile and an endpoint inside it.

cdnProfile: This is the container for your CDN settings. It uses the Standard Microsoft SKU.

cdnEndpoint: This is where your content is delivered. It points to your origin server (like your website) and allows both HTTP and HTTPS traffic.

The dependsOn ensures the profile is created before the endpoint.

Commands
Create a resource group to hold your Azure CDN profile and endpoint. This groups related resources together.
Terminal
az group create --name exampleResourceGroup --location eastus
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup", "location": "eastus", "managedBy": null, "name": "exampleResourceGroup", "properties": { "provisioningState": "Succeeded" }, "tags": {}, "type": "Microsoft.Resources/resourceGroups" }
--name - Sets the name of the resource group.
--location - Sets the Azure region for the resource group.
Deploy the Bicep template to create the CDN profile and endpoint inside the resource group.
Terminal
az deployment group create --resource-group exampleResourceGroup --template-file azure-cdn-profile-endpoint.bicep
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup/providers/Microsoft.Resources/deployments/deploymentName", "name": "deploymentName", "properties": { "provisioningState": "Succeeded", "outputs": {} } }
--resource-group - Specifies the resource group to deploy to.
--template-file - Specifies the Bicep template file to deploy.
Check the details of the CDN endpoint to confirm it was created and see its settings.
Terminal
az cdn endpoint show --resource-group exampleResourceGroup --profile-name exampleCdnProfile --name exampleCdnEndpoint
Expected OutputExpected
{ "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/exampleResourceGroup/providers/Microsoft.Cdn/profiles/exampleCdnProfile/endpoints/exampleCdnEndpoint", "name": "exampleCdnEndpoint", "properties": { "hostName": "exampleCdnEndpoint.azureedge.net", "originHostHeader": "www.example.com", "origins": [ { "name": "origin1", "properties": { "hostName": "www.example.com" } } ], "isHttpAllowed": true, "isHttpsAllowed": true }, "type": "Microsoft.Cdn/profiles/endpoints" }
--resource-group - Specifies the resource group of the CDN endpoint.
--profile-name - Specifies the CDN profile name.
--name - Specifies the CDN endpoint name.
Key Concept

If you remember nothing else from this pattern, remember: Azure CDN profiles organize your CDN settings, and endpoints are the specific addresses that deliver your cached content to users.

Common Mistakes
Trying to create a CDN endpoint before creating the CDN profile.
The endpoint depends on the profile, so it cannot be created first.
Always create the CDN profile first, then create endpoints inside it.
Not specifying the correct origin hostname in the endpoint configuration.
The CDN won't know where to get the original content, so caching and delivery will fail.
Set the origin hostname to your actual web server or storage endpoint.
Forgetting to allow HTTPS on the CDN endpoint.
Users may get security warnings or be unable to access content securely.
Enable HTTPS by setting isHttpsAllowed to true in the endpoint properties.
Summary
Create a resource group to hold your Azure CDN resources.
Deploy a Bicep template that creates a CDN profile and an endpoint with your origin server.
Verify the CDN endpoint details to ensure it is set up correctly and ready to deliver content.