AWS通过API更新CDN突然导致错误

时间:2019-01-06 14:14:28

标签: amazon-web-services .net-core amazon-cloudfront

我编写了一个用于更新CDN CNAME的API。

使用AWS开发工具包.netcore进行了此操作。

它曾经可以正常工作,突然(可能是几个星期),如果我再次发出没有任何更改的请求(结果为100),它开始以500响应UpdateDistributionAsync(尽管它确实进行了更新)。 尝试使用谷歌搜索功能,并意识到可能与ETag不是最新版本有关。尽管我每次进行更新时都要求发布,所以它应该是最新的ETag。

例外消息-

The request failed because it didn't meet the preconditions in one or more 
request-header fields.

我的代码示例-

        GetDistributionConfigResponse DistributionCDN = await client.GetDistributionConfigAsync(new GetDistributionConfigRequest(DistributionId));

        List<string> cnames = DistributionCDN.DistributionConfig.Aliases.Items;

        //remove domain and *.domain from additional names list.
        cnames = cnames.Where(domain => !request.RemoveDomains.Any(innerDomain => innerDomain == domain.Replace("*.", string.Empty) || innerDomain == domain.Replace("www.", string.Empty))).ToList();

        //add domain and *.domain to additional names list.
        foreach (string domain in request.AddDomains)
        {
            if(cnames.Contains(domain) == false)
            {
                cnames.Add(domain);
                cnames.Add("*." + domain);
            }
        }

        DistributionCDN.DistributionConfig.Aliases.Items = cnames;
        DistributionCDN.DistributionConfig.Aliases.Quantity = cnames.Count;



        UpdateDistributionResponse response =  await client.UpdateDistributionAsync(new UpdateDistributionRequest(DistributionId
            , DistributionCDN.ETag
            , DistributionCDN.DistributionConfig));

        if (response.HttpStatusCode != HttpStatusCode.OK)
        {
            return false;
        }
        return true;

文档链接-https://docs.aws.amazon.com/sdkfornet/v3/apidocs/

感谢阅读,欢呼

0 个答案:

没有答案