Search code examples
amazon-web-servicesjenkinsamazon-cloudfrontpipelineaws-cli

Why aws cli dont invalidate correctly the cache - AWS Cloudfront


I have created a Jenkins job that invalidate the cache each time that my frontend project is deployed. The issue is that although the AWS Website display that the cache is invalidating, when the job finish, the cache isnt completly cleaned, so I need to invalidate it manually through the AWS Website...

The way to invalidate the cache automatically that I used is through aws container where I execute the following command:

  • aws cloudfront create-invalidation --distribution-id ${DISTRIBUTION_ID} --paths /* > output.json

The output file will contain a json where I can get differents keys: values. Two of they that I use is Id and Status. Once the invalidation was created, I another pipeline step I execute the following:

  • aws cloudfront get-invalidation --distribution-id ${DISTRIBUTION_ID} --id ${id_invalidator} > status_invalidation.json

With the previously command I quest to the API each 50 second (through a sleep 50) the status of the invalidation. When the validation return a `Status = Completed', the job is finished. This condition are inside a while loop.

Someone know why this is happened?


Solution

  • You always have to quote expressions with the * character on the command line, to avoid local shell expansion. The correct syntax is this:

    --paths '/*'
    

    Otherwise you are trying to invalidate names based on what's in the root directory on your local filesystem (as captured by the *, expanded by the shell).