How to use AWS cli for cloudfront invalidation

The only tricky thing is the path attribute of the invalidation-batch.
The AWS documentation is lack of details and example, spent me couple of hours just to test how to make it work.
Ref:AWS-cli create-invalidation

to run the command:

aws cloudfront create-invalidation --cli-input-json file://./data.json

the json format could checked by:

aws cloudfront create-invalidation --generate-cli-skeleton

the sample format is:

{
  "DistributionId": "",
  "InvalidationBatch": {
    "Paths": {
      "Quantity": 0,
      "Items": [ "" ]
    },
  "CallerReference": ""
  }
}

For each attribute, information could be gathered from:
DistributionId: in AWS CloudFront, Check Distribution ID
Quantity: need to comply with the number of items that listed in the “Items” attribute, maximum is 300, error message will be prompted if more than this amount
Items: remember to add “/” in front to specify the path in cloudfront. It is tested that no single quote is accepted by AWS CLI
CallerReference: It is a user specified attribute, recommended to use timestamp. On linux, timestamp could be generated by “date +%s”

Example:

{
  "DistributionId": "XXXXXXXXXXXXX",
  "InvalidationBatch": {
    "Paths": {
      "Quantity": 6,
      "Items": [
        "/styles/sheik.jpg",
        "/styles/shwe.jpg",
        "/styles/shwedagonwhiskey.jpg",
        "/styles/shwemann_copy.jpg",
        "/styles/shwemann_copy_0.jpg",
        "/styles/shwe_0.jpg"
      ]
    },
  "CallerReference": "1437043416"
  }
}
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s