public async Task <string> CreateInvalidation(string distributionId) { var callerReference = Guid.NewGuid().ToString(); var createInvalidationResponse = await amazonCloudFrontClient.CreateInvalidationAsync(new CreateInvalidationRequest() { DistributionId = distributionId, InvalidationBatch = new InvalidationBatch() { Paths = new Paths() { Items = new List <string>() { "/*" }, Quantity = 1 }, CallerReference = callerReference } }); return(createInvalidationResponse.Invalidation.Id); }
/// <summary> /// Invalidates objects from a CloudFront distribution. /// </summary> /// <param name="distributionId">The distribution to invalidate objects from.</param> /// <param name="items">The path of the objects to invalidate.</param> /// <param name="reference">A unique name that ensures the request can't be replayed.</param> /// <param name="settings">The <see cref="CloudFrontSettings"/> required to connect to Amazon CloudFront.</param> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> public async Task <string> CreateInvalidation(string distributionId, IList <string> items, string reference, CloudFrontSettings settings, CancellationToken cancellationToken = default(CancellationToken)) { //Get Reference if (String.IsNullOrEmpty(reference)) { reference = DateTime.Now.Ticks.ToString(); } //Correct Paths List <string> paths = new List <string>(); foreach (string item in items) { if (!item.StartsWith("/")) { paths.Add("/" + item); } else { paths.Add(item); } } //Create Request InvalidationBatch batch = new InvalidationBatch() { Paths = new Paths() { Items = paths.ToList(), Quantity = items.Count }, CallerReference = reference }; CreateInvalidationRequest request = new CreateInvalidationRequest() { DistributionId = distributionId, InvalidationBatch = batch }; //Send Request _Log.Verbose("Create Invalidation {0}", distributionId); AmazonCloudFrontClient client = this.GetClient(settings); CreateInvalidationResponse response = await client.CreateInvalidationAsync(request); if (response.HttpStatusCode == System.Net.HttpStatusCode.Created) { return(response.Invalidation.Id); } else { _Log.Error("Error invalidating object {0}", distributionId); return(""); } }