AWS CLI で CloudFront のキャッシュを削除する

awscli から CloudFront のキャッシュ削除 (Create Invalidation) を行うには以下のように実行します。

aws cloudfront create-invalidation --distribution-id ABCD0123456789 --paths "/T*"

これを実行するには IAM で最低限、下記の権限が付与されている必要があります。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CFResourceLevelPermission",
      "Effect": "Allow",
      "Action": ["cloudfront:CreateInvalidation"],
      "Resource": "arn:aws:cloudfront::012345678901:distribution/ABCD0123456789"
    }
  ]
}