2017年4月9日

AWS CLIでCloudfrontのキャッシュクリア

Share

公式ドキュメント

AWS CLI コマンドの実行

頻度とかファイル数にもよるけど、とりあえずざっくり全クリア。

XXXXXXXXXXXXXXはdistribution-id、確認方法はこちらで。

$ aws cloudfront list-distributions

$ aws cloudfront create-invalidation --distribution-id XXXXXXXXXXXXXX --paths '/*'
AWS CLI support for this service is only available in a preview stage.

However, if you'd like to use the "aws cloudfront" commands with the
AWS CLI, you can enable this service by adding the following to your CLI
config file:

    [preview]
    cloudfront=true

or by running:

    aws configure set preview.cloudfront true

なんかメッセージでたので指示どおり実行

$ aws configure set preview.cloudfront true
$ aws cloudfront create-invalidation --distribution-id XXXXXXXXXXXXXX --paths '/*'
{
    "Invalidation": {
        "Status": "InProgress",
        "InvalidationBatch": {
            "Paths": {
                "Items": [
                    "/*"
                ],
                "Quantity": 1
            },
            "CallerReference": "cli-XXXXXXXXXXXX-XXXXX"
        },
        "Id": "XXXXXXXXXXXXXX",
        "CreateTime": "2017-04-09T01:54:42.985Z"
    },
    "Location": "https://cloudfront.amazonaws.com/2016-11-25/distribution/E3L5CA48AGLO7U/invalidation/I2BB6FIQJYY9GS"
}