Azure CDN Management Client Library

13.1.1 · active · verified Thu Apr 09

The Azure CDN Management Client Library for Python provides programmatic access to manage Azure Content Delivery Network (CDN) resources. It allows users to create, configure, update, and delete CDN profiles, endpoints, and custom domains. Part of the broader Azure SDK for Python, it follows the SDK's consistent design principles and release cadence, typically receiving updates as new Azure API versions are released or significant changes occur in the underlying service, often with minor version bumps and major version updates for breaking changes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and list existing CDN profiles in your subscription. Ensure the `AZURE_SUBSCRIPTION_ID` environment variable is set. It highlights the typical pattern for creating the client and iterating over paginated results.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.cdn import CdnManagementClient

# --- Configuration ---
# Ensure AZURE_SUBSCRIPTION_ID is set in your environment variables.
# You can also set AZURE_TENANT_ID, AZURE_CLIENT_ID, AZURE_CLIENT_SECRET for service principal auth.

AZURE_SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID", "")

if not AZURE_SUBSCRIPTION_ID:
    print("Please set the AZURE_SUBSCRIPTION_ID environment variable.")
    exit(1)

print(f"Using Subscription ID: {AZURE_SUBSCRIPTION_ID}")

# Authenticate with Azure using DefaultAzureCredential
# This credential chain attempts to authenticate via various methods:
# Environment variables, Managed Identity, Visual Studio Code, Azure CLI, Azure PowerShell.
credential = DefaultAzureCredential()

# Create a CDN management client
# All CDN operations are performed through this client object.
client = CdnManagementClient(credential, AZURE_SUBSCRIPTION_ID)

print("\nListing CDN Profiles in the subscription...")
# List all CDN profiles. This returns an iterator (ItemPaged).
# Iterating directly fetches pages as needed.
cdn_profiles = client.profiles.list()

profile_count = 0
for profile in cdn_profiles:
    profile_count += 1
    print(f"  - Profile Name: {profile.name}, Location: {profile.location}, Sku: {profile.sku.name}")

if profile_count == 0:
    print("  No CDN profiles found in this subscription.")
else:
    print(f"Found {profile_count} CDN profile(s).")

# Example of a long-running operation (creation of a CDN profile)
# This would typically involve a begin_ method and a poller.
# resource_group_name = "myResourceGroup"
# profile_name = "myUniqueCdnProfile"
# profile_parameters = {
#     "location": "westus",
#     "sku": {"name": "Standard_Microsoft"}
# }
# print(f"\nStarting creation of CDN Profile '{profile_name}'...")
# poller = client.profiles.begin_create(resource_group_name, profile_name, profile_parameters)
# profile = poller.result() # Wait for the operation to complete
# print(f"CDN Profile '{profile.name}' created successfully.")

view raw JSON →