AWS CodeBuild local cache failing to actually cache?

I have been trying to make the cache work myself with limited success.

Not from any public source, but these are some observations:

  • The cache will only be avilable if the build time is more than 5 minutes.

  • Cache can be used if the new build is successfully placed on the same build host.

  • Cache can be used if the new build is being run within 5-15 minutes of the last build. Cache may stay available based on the last build time with a max of 15 minutes.

  • Despite builds exceeding 5 minutes, the cache may not always work probably due to build being placed on different build host.

  • Additionally, in the case where the cache speeds up the new build to below 5 minutes, that build will not be cached resulting in subsequent miss.

While I trust CodeBuild engineers had good reasons to design it this way, the above limitations renders this local cache functionality of limited use in my opinion.


The documentation isn't exactly clear, but AWS CodeBuild Local cache can only cache directories (as of time of writing). This is slightly confusing because the AWS CodeBuild buildspec specification allows the path to be individual files or a wildcard, but in reality specifying a file will yield an error.

Unable to initialize cache download: only directories can be cached locally: ...

In your example you use specify the cache as

cache:
  paths:
    - '/root/foo/*'

Where * would refer to all individual files and folders inside foo but only folders would be cached.

Specifying the entire directory should work

cache:
  paths:
    - /root/foo/