LoginSignup
0
0

More than 3 years have passed since last update.

コマンドラインから(awscliで)CloudFrontのキャッシュ無効化する

Last updated at Posted at 2021-02-25

手順

3つのコマンドを実行して達成可能。

  1. CloudFront の disutribution id を入手
  2. パスを無効化する
  3. 無効化の進捗状況を確認する

例の内訳

{profile}
認証情報のプロファイル
{hostname}
ドメイン割り当て済みならFQDN
{path}
無効化するパス。例えば/aaa/bbb.json

$ aws cloudfront list-distributions --profile {profile} | jq '.DistributionList.Items[] | .Id + " " + .Aliases.Items[0]' -r
E************ {hostname}
...

$ aws cloudfront create-invalidation --distribution-id E************ --paths "{path}" --profile {profile}
{
    "Location": "https://cloudfront.amazonaws.com/2020-05-31/distribution/E************/invalidation/I17***********",
    "Invalidation": {
        "Id": "I17***********",
        "Status": "InProgress",
        "CreateTime": "2021-02-22T12:47:09.866Z",
        "InvalidationBatch": {
            "Paths": {
                "Quantity": 1,
                "Items": [
                    "{path}"
                ]
            },
            "CallerReference": "cli-0000000000-000000"
        }
    }
}

$ aws cloudfront get-invalidation --id I17*********** --distribution-id E************ --profile {profile} | jq -r '.Invalidation | .CreateTime + " " + .Status'
2021-02-22T12:47:09.866Z Completed

$ aws cloudfront get-invalidation --id I17*********** --distribution-id E************ --profile {profile}
{
    "Invalidation": {
        "Id": "I17***********",
        "Status": "Completed",
        "CreateTime": "2021-02-22T12:47:09.866Z",
        "InvalidationBatch": {
            "Paths": {
                "Quantity": 1,
                "Items": [
                    "{path}"
                ]
            },
            "CallerReference": "cli-0000000000-000000"
        }
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0