How to purge CDN files in an Azure Akamai profile
CDN systems also can cache assets – they keep a copy of your images and don’t need to fetch them from the original source. This can raise challenges when you have assets that become out of date (for example, a banner with an offer), but you can still use a CDN and set it for a given timeframe, such as a one-week cache.
We had this challenge recently on a client project, for which we had some images in our Microsoft Azure CDN.
We were using the Akamai Profile – Akamai are a leader in the CDN world and were the provider of choice as they also offer new features such as HTTP2.
We had a lot of images (Over 20,000) that needed to be purged. However it seems that in the standard Azure portal, there isn’t a “purge all” option for Akamai and wildcards (/*) didn’t seem to be supported or honoured when we were using it.
After a lot of Googling and no joy, I contacted Azure support, who pointed me in the direction of a PowerShell command that would do the trick. To save you some time, I thought I would share it here!
Some notes on the variables:
- the endpoint needs to the base name of the endpoint, not the full URL (eg. “my-cdn” rather than “my-cdn.azureedge.net”)
- You can wild card through the PowerShell interface, so using “/my-images/*” will purge everything under the my-images folder
- Open Powershell in an elevated permission mode such as Administrator:
Connect to your Azure account using the following command:
- Enter the following variables with your correct settings:
$ResourceGroupName = “YourResourceGroupName”
$ProfileName = “YourCDNProfile”
$EndpointName = “YourCDNEndpoint”
$PurgeFolder = “ThePathOnYourCDNYouWishToPurge”
- Run the following command to purge your content:
Unpublish-AzureRmCdnEndpointContent -ResourceGroupName $ResourceGroupName -ProfileName $ProfileName -EndpointName $EndpointName -PurgeContent $PurgeFolder