CloudFront 创建失效的 AWS CLI returns 旧失效

AWS CLI for CloudFront create-invalidation returns old invalidation

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

我正在安装并启用云端:

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.