amazon-web-services - 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
andDistributionConfig
字段复制到您的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();
}
推荐阅读
- r - 如何总结R中某个区域的观察发生情况?
- java - 如何在邮递员中为此特定方法传递请求参数?
- pine-script - 如何检查窗格是否为对数比例?
- node.js - 防止 Mongo DB 中的重复文档
- python - 如何根据 M2M 关系在 django 模型中自动填充 IntegerField?
- java - 使用复合键的 JPA 多对一映射
- javascript - react-beautiful-dnd:拖放列表时防止闪烁
- css - 修改 AG-grid cell 工具提示的 z-index
- javascript - 如何使用 reactjs 在 webapps 上获取特定的移动设备型号?
- jquery - 如何在jQuery中手动将表单设置为无效