AWS CLI CloudFront Invalidate All Files

21,698

Solution 1

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.

Solution 2

Example of invalidation of cloudfront distribution via aws cli :

aws cloudfront create-invalidation --distribution-id <DistributionID> --paths "/*"

Example :

aws cloudfront create-invalidation --distribution-id E1B1A4GHK9TTE --paths "/*"

To list or get cloudfront distribution id you can use console or via cli :

aws cloudfront list-distributions 
aws cloudfront list-distributions | grep Id

Solution 3

Maybe on windows (using cmd) you can use the path without quotes, but on bash environment (linux, mac) the character * it's a special char. You need to pass the path inside quotes to work cross-platform:

aws cloudfront create-invalidation --distribution-id $DISTRIBUTION_ID --paths '/*'
Share:
21,698

Related videos on Youtube

neutreno
Author by

neutreno

Updated on July 09, 2022

Comments

  • neutreno
    neutreno almost 2 years

    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
            }, 
    
  • damusix
    damusix almost 7 years
    This did the trick for me. Thank you Michael. To further contribute, on version aws-cli/1.11.36 Python/2.7.12 Darwin/16.4.0 botocore/1.4.93, using the --paths '*' value gives the error: An error occurred (InvalidArgument) when calling the CreateInvalidation operation: Your request contains one or more invalid invalidation paths. You should use --paths '/*' instead for a successful response
  • Michael - sqlbot
    Michael - sqlbot almost 7 years
    @damusix thanks for the tip on the need for the leading /. Updated accordingly.
  • Vladyslav Didenko
    Vladyslav Didenko over 4 years
    this was not entire correct path specification. Atleast on my windows console using this kind of path cause an error. This should be in double quotes (windows atleast) You must use --paths "/*"
  • Josh Woodcock
    Josh Woodcock over 3 years
    I was using gitbash with windows and having a problem. I had to add MSYS_NO_PATHCONV=1 prefix to my command. eg: MSYS_NO_PATHCONV=1 aws cloudfront create-invalidation ...
  • minigeek
    minigeek about 2 years
    thank u, finally this worked!