AWS CloudFront "TooManyInvalidationsInProgress" in CI
CloudFront capped concurrent invalidations: "TooManyInvalidationsInProgress" means the distribution already has the maximum in-progress invalidations (15) and refuses another until some complete.
What this error means
aws cloudfront create-invalidation fails with "An error occurred (TooManyInvalidationsInProgress) when calling the CreateInvalidation operation". It happens when many deploys or per-file invalidations run close together.
An error occurred (TooManyInvalidationsInProgress) when calling the CreateInvalidation
operation: Your request contains more invalidations in progress than are allowed per distribution.Common causes
Per-file invalidations flood the queue
Invalidating each changed file as its own request quickly reaches the 15 in-progress limit on a busy deploy.
Overlapping deploys each invalidate
Concurrent pipelines or a rerun stack multiple invalidations on the same distribution at once.
How to fix it
Invalidate with a single wildcard path
- Replace many per-file invalidations with one wildcard invalidation.
- Use "/*" for a full purge or a prefix like "/assets/*" for a subtree.
- Wait for it to complete before starting another.
aws cloudfront create-invalidation \
--distribution-id "$DISTRIBUTION_ID" \
--paths "/*"Serialize deploys to one distribution
Use a concurrency gate so only one deploy invalidates the distribution at a time.
concurrency:
group: deploy-${{ github.ref }}
cancel-in-progress: falseHow to prevent it
- Prefer one wildcard invalidation over many per-file calls.
- Gate deploys to a distribution with a concurrency group.
- Poll GetInvalidation so overlapping runs do not stack.