Search code examples
asp.netamazon-cloudfront

Amazon CloudFront invalidation in ASP.Net


I am not sure how to send a request using ASP.Net to Amazon CloudFront to invalidate an object.

The details are here http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?Invalidation.html but I am not sure how to implement this in ASP.Net.


Solution

  • The accepted answer no longer works as of the latest version of the AWS SDK for .NET (1.5.8.0). This should do the trick:

    using Amazon;
    using Amazon.CloudFront.Model;
    

    ...

    var client = AWSClientFactory.CreateAmazonCloudFrontClient(accessKey, secretKey);
    client.CreateInvalidation(new CreateInvalidationRequest {
        DistributionId = distributionID,
        InvalidationBatch = new InvalidationBatch {
            Paths = new Paths {
                Quantity = arrayofpaths.Length,
                Items = arrayofpaths.ToList()
            },
            CallerReference = DateTime.Now.Ticks.ToString()
        }
    });