amazon-web-services - CloudFront 创建失效的 AWS CLI 返回旧失效

标签 amazon-web-services amazon-cloudfront aws-cli

我正在尝试使用 AWS CLI 在我的 CI 服务中的 CloudFront 上创建失效,以在部署时自动使文件失效。但是,CLI 返回一条成功消息,但引用的失效是一个月前的,并且没有创建新的失效。

我正在安装并启用云端:

pip install awscli
aws configure set preview.cloudfront true
aws configure set preview.create-invalidation true

然后我创建失效:

aws cloudfront create-invalidation --cli-input-json '{"DistributionId":"ABC123ABC123","InvalidationBatch":{"Paths":{"Quantity":1,"Items":["/index.html"]},"CallerReference":"codeship"}}'

响应示例,当我在美国东部时间 7 月 13 日下午 4 点运行此命令时:

{
  "Invalidation": {
    "Status": "Completed",
    "InvalidationBatch": {
      "Paths": {
        "Items": [
          "/index.html"
        ],
        "Quantity": 1
      },
      "CallerReference": "codeship"
    },
    "Id": "1234567890",
    "CreateTime": "2015-06-12T18:39:56.360Z"
  },
  "Location": "https://cloudfront.amazonaws.com/2015-04-17/distribution/ABC123ABC123/invalidation/1234567890"
}

当我登录到 CloudFront 时,我可以看到 6 月 12 日的一个失效,但昨天运行此命令时什么也没有。

我做错了什么吗?这个 CLI API 还能用吗?

最佳答案

看起来您在每次调用 CreateInvalidation 时都传递了相同的 CallerReference? CallerReference 唯一标识特定的失效请求,因此 CloudFront 会为您提供使用该 CallerReference 的第一次失效的结果。来自documentation :

A value that you specify to uniquely identify an invalidation request. CloudFront uses the value to prevent you from accidentally resubmitting an identical request. Whenever you create a new invalidation request, you must specify a new value for CallerReference and change other values in the request as applicable. One way to ensure that the value of CallerReference is unique is to use a timestamp, for example, 20120301090000.

If you make a second invalidation request with the same value for CallerReference, and if the rest of the request is the same, CloudFront doesn't create a new invalidation request. Instead, CloudFront returns information about the invalidation request that you previously created with the same CallerReference.

If CallerReference is a value you already sent in a previous invalidation batch request but the content of any Path is different from the original request, CloudFront returns an InvalidationBatchAlreadyExists error.

关于amazon-web-services - CloudFront 创建失效的 AWS CLI 返回旧失效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31408410/

相关文章:

amazon-web-services - AWS CLI - [SSL : CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl. c:1056)

python - 使用 AWS Chalice 生成 PDF

amazon-web-services - 如何在 HTTPS 云前端后面使用 AWS 亚马逊云前端将非 WWW 转发到 WWW

javascript - 将带有随机数的 CSP header 添加到 Lambda Edge

redirect - Cloudfront 使用 SSL 将 www 重定向到裸域

aws-cloudformation - 从 aws cloudformation 描述堆栈获取输出

visual-studio - 无法从Visual Studio(或实际任何地方)连接到AWS EC2

amazon-web-services - S3到S3的POST请求,响应为405

angularjs - Angular 和 Cloudfront 与 Safari

amazon-web-services - AWS CLI S3API在路径中找到最新文件夹