Skip to content

WordPress からプラグインで AWS CloudFront のキャッシュを削除する

WordPress の C3 Cloudfront Cache Controller プラグインを使うと WordPress の管理画面から AWS CloudFront のキャッシュを削除することが出来ます。 今回はこのプラグインのインストール方法とキャッシュ削除方法をメモしておきます。

検証環境

対象 バージョン
Amazon Linux 2023.6.20250303
Apache 2.4.62
MariaDB Server 10.5.25
PHP 8.3.16

必要な IAM 権限

readme.txt に記載されていますが、このプラグインを動作させるには以下のような IAM ポリシーが必要になります。

全ての CloudFront Distribution のキャッシュを削除する場合の IAM ポリシー

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "cloudfront:GetDistribution",
        "cloudfront:ListInvalidations",
        "cloudfront:GetStreamingDistribution",
        "cloudfront:GetDistributionConfig",
        "cloudfront:GetInvalidation",
        "cloudfront:CreateInvalidation"
      ],
      "Effect": "Allow",
      "Resource": "*"
    }
  ]
}

特定 CloudFront Distribution のキャッシュを削除する場合の IAM ポリシー

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "cloudfront:GetDistribution",
        "cloudfront:ListInvalidations",
        "cloudfront:GetStreamingDistribution",
        "cloudfront:GetDistributionConfig",
        "cloudfront:GetInvalidation",
        "cloudfront:CreateInvalidation"
      ],
      "Effect": "Allow",
      "Resource": "arn:aws:cloudfront::012345678901:distribution/ABCD0123456789"
    }
  ]
}

プラグインのインストール

WordPress へログインし、プラグインをインストールします。

Step.1

プラグイン新規プラグインを追加 をクリックします。

file

Step.2

プラグインの検索C3 Cloudfront Cache Controller と入力して検索し、表示されたプラグインの 今すぐインストール をクリックします。

file

Step.3

有効化 をクリックします。

file

Step.4

これでプラグインが有効化されました。

file

Step.5

設定CloudFront Settings をクリックします。

file

Step.6

以下 3 点の必要情報を入力します。

  1. CloudFront Distribution ID
  2. AWS Access Key
  3. AWS Secret Key

file

CloudFront Distribution ID は CloudFront の管理画面から確認します。

file

プラグインから CloudFront のキャッシュを削除する

プラグインから CloudFront のキャッシュを削除するには Flush All Cache をクリックします。

file