AWS CLI CloudFront Invalidate All Files

neutreno picture neutreno · Jun 11, 2016 · Viewed 10.7k times · Source

I am attempting to invalidate an entire static website. The following command does not seem to invalidate /index.html and gives an odd output of items to be invalided, as shown below. Is this AWS CLI behaviour normal or am I missing something? Thanks!

aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths /*

Output:

{
    "Invalidation": {
    "Status": "InProgress", 
    "InvalidationBatch": {
        "Paths": {
            "Items": [
                "/lib32", 
                "/home", 
                "/vmlinuz", 
                "/core", 
                "/proc", 
                "/var", 
                "/dev", 
                "/usr", 
                "/etc", 
                "/initrd.img", 
                "/cdrom", 
                "/lost+found", 
                "/root", 
                "/tmp", 
                "/lib", 
                "/dead.letter", 
                "/lib64", 
                "/boot", 
                "/sys", 
                "/run", 
                "/bin", 
                "/sbin", 
                "/mnt", 
                "/opt", 
                "/snap", 
                "/media", 
                "/copyright", 
                "/srv"
            ], 
            "Quantity": 28
        }, 

Answer

Michael - sqlbot picture Michael - sqlbot · Jun 11, 2016

That's your shell doing expansion of local filenames.

That's what you're essentially asking for since the * isn't quoted.

Either --paths '*' or Specifying --paths '/*'¹ will do what you intend. Quoting the wildcard keeps it as a literal string rather than what you're seeing.


¹The CloudFront console allows you to specify either * or /* to invalidate the entire distribution; by contrast, the CLI expects /*. This, in turn, is because the underlying API also expects /*. When you use * in the console, the leading slash is silently added by the console before the console makes the request to the CloudFront API.