Sitefinity AWS CloudFront Invalidation
sitefinity | NET, CMS, Sitefinity | 2023-01-20
I have implemented create
- an intercepter to listen Sitefinity Page Published event
- a cache invalidation trigger to AWS CloudFront
AWS Setup
Of course CloudFront has to be already setup. Here we are going to setup a middleman user, to power the interface to work.
- Create a policy cf-createinvalidation-policy with the permission of CreateInvalidation in CloudFront with All Resources (Wildcard)
-
Create user groups cf-usergroup, attach the policy cf-createinvalidation-policy
-
Create a user cf-middleman, add to user group cf-usergroup
-
Create Access keys from cf-middleman, choose Application running outside AWS and name it as cf-sf
-
Use the access keys to run the code later
Sitefinity
I built it as a seperated module in order to plug and play in different solution and version.
You can follow the steps to setup external library to plug in and play on Sitefinity.
- In last line of AssemblyInfo.cs file, insert
[assembly: PreApplicationStartMethod(typeof(SparksEventSubscriber), "Start")]
-
Create a SparksEventSubscriber.cs file, and a SparksEventSubscriber.cs file
-
Create a sparksSetting.json file
{
"CloudFront": {
"Profile": "",
"DistributionId": "",
"AccessKeyId": "",
"AccessKey": ""
}
}
-
Build the project
-
For deployment, copy AWSSDK.CloudFront.dll, AWSSDK.Core.dll (if missing from destination), SparksCloudFront.dll and sparksSetting.json to Sitefinity Project
-
Edit the sparksSetting.json to the relevant project credentials
Finally, go to one of the Page setup in Sitefinity instance, publish and you will see all relevant URLs will be submit for Cache Invalidation.
How to upgrade or download for different Sitefinity version?
Very simple, just go to Manage Nuget Packages screen, change the package source to Sitefinity NuGet Source
Update Telerik.Sitefinity.Core to the desired version.