CloudFront is AWS’ CDN. As with any CDN (or any cache for that matter), sometimes you need to clear it in a hurry. In CloudFront, this is don’t with an invalidation and “a hurry” means about 15 minutes. More waiting. The AWS console give you a spinner, but who wants to stare at that?
If you have the AWS CLI installed, you can get the status of an
invalidation using the
aws cloudfront get-invalidation command.
1 2 3 4
It takes two arguments, the ID of the invalidation and the ID of the CloudFront distribution. You could get fancier and create the invalidation from the CLI as well, but I usually do it in the GUI, cut and pasting the IDs.
One refinement from my ping and Netcat wait functions, I’m using
until is identical to
while !, but makes your intentions
clearer. I simply didn’t know about it when I developed my earlier
The above approach works fine, the AWS CLI actually provides an easier
way to wait, the
wait command. However, it’s in beta and before you
can use it you need to enable it with:
You call it thusly:
Which lets us rewrite the function as:
1 2 3
Since the AWS command does the waiting for us, this version of the
function doesn’t need a loop.
&& will execute the notification
function only if the
wait exits without an error. If the
with an error, say an invalid ID the
&& insures that the doesn’t
Now, if you wanted to be really cool, you could start the invalidation from the command line, capture the invalidation ID and fire up the wait automatically. But I’m too lazy. If you’re not, share it in the comments.