我编写了一些使用Java API创建和删除CloudFront分配的Scala代码。
有问题的代码是removeDistribution method。输出是:
Disabling distribution of scalacoursesdemo.s3.amazonaws.com with id E3656VVNINIXI3 and ETag E3W3IUM6RJKTDY
distributionConfig={
"enabled" : false,
"restrictions" : {
"geoRestriction" : {
"restrictionType" : "none",
"items" : [ ],
"quantity" : 0
}
},
"priceClass" : "PriceClass_All",
"defaultRootObject" : "index.html",
"logging" : {
"enabled" : false,
"bucket" : "",
"prefix" : "",
"includeCookies" : false
},
"customErrorResponses" : {
"items" : [ ],
"quantity" : 0
},
"aliases" : {
"items" : [ ],
"quantity" : 0
},
"cacheBehaviors" : {
"items" : [ ],
"quantity" : 0
},
"origins" : {
"items" : [ {
"id" : "S3-scalacoursesdemo",
"customOriginConfig" : null,
"s3OriginConfig" : {
"originAccessIdentity" : ""
},
"domainName" : "scalacoursesdemo.s3.amazonaws.com"
} ],
"quantity" : 1
},
"comment" : "",
"callerReference" : "284851146697",
"defaultCacheBehavior" : {
"targetOriginId" : "S3-scalacoursesdemo",
"minTTL" : 3600,
"viewerProtocolPolicy" : "allow-all",
"trustedSigners" : {
"enabled" : false,
"items" : [ ],
"quantity" : 0
},
"allowedMethods" : {
"items" : [ "GET", "HEAD" ],
"quantity" : 2
},
"smoothStreaming" : false,
"forwardedValues" : {
"queryString" : false,
"cookies" : {
"forward" : "all",
"whitelistedNames" : null
}
}
},
"viewerCertificate" : {
"SSLSupportMethod" : null,
"cloudFrontDefaultCertificate" : true,
"IAMCertificateId" : null
}
}
Update result ETag = E14HGEUEBH4TKO
Deleting distribution of scalacoursesdemo.s3.amazonaws.com with id E3656VVNINIXI3 and ETag E14HGEUEBH4TKO.
deleteDistributionRequest={
"id" : "E3656VVNINIXI3",
"requestClientOptions" : {
"clientMarker" : null
},
"ifMatch" : "E14HGEUEBH4TKO",
"requestMetricCollector" : null,
"requestCredentials" : null
}
Distribution of scalacoursesdemo.s3.amazonaws.com with id 'E3656VVNINIXI3' and ETag 'E3W3IUM6RJKTDY':
The distribution you are trying to delete has not been disabled.
(Service: AmazonCloudFront; Status Code: 409; Error Code: DistributionNotDisabled; Request ID: ab6e9920-d3aa-11e3-a498-7f333cd2eda0)
问题是AWS Web客户端是否将分发显示为已禁用。如果我然后尝试使用CloudBerry,它也无法删除分发。大约一个小时后,问题就消失了,CloudBerry能够删除该发行版。
如果我在由CloudBerry创建的另一个发行版上重新运行我的程序,它会禁用发布,然后生成此错误:
The precondition given in one or more of the request-header fields evaluated to false.
该错误消息最无益。我可以看到列出here。我认为这意味着ifMatch
ETag不正确。不知道从哪里获得这个价值。
BTW,我想我在CloudFront docs中发现了一个错误。我认为应该从最近的If-Match
或GET
操作中的eTag设置PUT
值,而不是The value of the ETag header you received when you disabled the distribution
更为正确。
我尝试在创建发行版后等待3秒,并在删除它之前等待3秒钟禁用它,但这没有帮助。
我的程序显然有问题,但我没有看到它。建议?
答案 0 :(得分:0)
在您的GET请求(getDistribution)的回复中找到了对此的修复程序将会有一个' ETag'字段,将其传递给您的removeDistribution请求' IfMatch'它会成功通过。我正在使用带有aws-sdk的节点,所以它看起来像这样:
aws.removeDistribution({
Id: result.Id,
IfMatch: result.ETag,
}, function(err, response){console.log(err, response)});
希望这有帮助!