I'm trying to invalidate a single file on a AWS Cloudfront distribution using the (as of now) experimental aws cloudfront
CLI tool. I cannot figure out how to format the JSON it expects for passing to the --invalidation-batch
parameter.
The only documentation I found only explains the XML it expects, yet I am having a hard time translating that into JSON: http://docs.aws.amazon.com/AmazonCloudFront/latest/APIReference/CreateInvalidation.html
I tried:
{
"Paths" : {
"Quantity" : 1,
"Items" : ["/foobar.js"]
},
"CallerReference" : "foo-bar-baz"
}
Has anyone yet used this and figured out to format the JSON?
PDFRSS. If you need to remove a file from CloudFront edge caches before it expires, you can do one of the following: Invalidate the file from edge caches. The next time a viewer requests the file, CloudFront returns to the origin to fetch the latest version of the file.
Object invalidations typically take from 10 to 100 seconds to complete. You can check the status of an invalidation by viewing your distribution from the CloudFront console.
You can generate sample JSON using the following command.
$ aws cloudfront create-invalidation --generate-cli-skeleton | vi -
Output:
{
"DistributionId": "",
"InvalidationBatch": {
"Paths": {
"Quantity": 0,
"Items": [
""
]
},
"CallerReference": ""
}
}
Here's a complete, working example of doing it from a Bash script, including handling the need to create a unique id for each invalidation (unique enough here for my purposes):
INVALIDATION_ID=$(date +"%S")
INVALIDATION_JSON="{
\"DistributionId\": \"YOUR_ID\",
\"InvalidationBatch\": {
\"Paths\": {
\"Quantity\": 2,
\"Items\": [
\"/foo.png\",
\"/bar.jpg\"
]
},
\"CallerReference\": \"$INVALIDATION_ID\"
}
}"
aws cloudfront create-invalidation --cli-input-json "$INVALIDATION_JSON"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With