如何解决Cloudfront异常“缺少If-Match版本或对该资源无效”更新发行版时
使用AWS Node SDK更新Cloudfront发行版时,出现以下异常:
message:
'The If-Match version is missing or not valid for the resource.',code: 'InvalidIfMatchVersion',time: 2020-08-23T19:37:22.291Z,requestId: '43a7707f-7177-4396-8013-4a704b7b11ea',statusCode: 400,retryable: false,retryDelay: 57.05741843025996 }
我在做什么错了?
解决方法
发生此错误的原因是,您需要首先使用cloudfront.getDistributionConfig
获取当前的发行配置,然后将ETag
和DistributionConfig
字段复制到您的cloudfront.updateDistribution
调用中。您可以根据需要修改DistributionConfig
,以实现您要执行的实际配置更新。
文档在解释这一点上做得很差(说明仅针对REST API,而不是您使用的实际SDK)。
以下是通过拉动最新的分发配置,对其进行修改然后对其执行更新来更新要禁用的Cloudfront分发的示例:
async function disable_cloudfront_distribution(dist_id) {
// We need to pull the previous distribution config to update it.
const previous_distribution_config = await cloudfront.getDistributionConfig({
Id: dist_id
}).promise();
const e_tag = previous_distribution_config.ETag;
// Update config to be disabled
previous_distribution_config.DistributionConfig.Enabled = false;
// Create update distribution request with distribution ID
// and the copied config along with the returned etag for ifmatch.
const params = {
Id: dist_id,DistributionConfig: previous_distribution_config.DistributionConfig,IfMatch: e_tag
};
return cloudfront.updateDistribution(params).promise();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。