Appearance
CloudFront
Speedy clears CloudFront when pages change, with no AWS SDK, and keeps the cost down.
Speedy detects CloudFront from its X-Amz-Cf-Id or Via header and says so on the settings and utility pages.
Without keys
Speedy still caches on your server, and tells CloudFront not to keep HTML pages (Cache-Control: no-cache, s-maxage=0), so CloudFront never shows a page Speedy can’t clear.
With keys
- In AWS IAM, create a user (or role) with this policy, using your distribution’s ARN:json
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": "cloudfront:CreateInvalidation", "Resource": "arn:aws:cloudfront::123456789012:distribution/E1ABCDEF2GHIJK" } ] } - Create an access key for it, and add it to
.envwith the distribution ID:bashCLOUDFRONT_DISTRIBUTION_ID="E1ABCDEF2GHIJK" AWS_ACCESS_KEY_ID="…" AWS_SECRET_ACCESS_KEY="…" - In Settings → Plugins → Speedy Cache, enter
$CLOUDFRONT_DISTRIBUTION_ID. The AWS keys are read fromAWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEYwhen their fields are blank.AWS_SESSION_TOKENis used when it’s set. - On the utility page, click Test CloudFront. It sends one invalidation for a path no page uses.
Make sure your CloudFront cache policy respects the origin’s Cache-Control header, so pages are kept for as long as Speedy says.
Two more settings in the cache policy:
- Query strings: All. Speedy’s background rebuilds add a one-off query string to reach your server. If CloudFront ignores query strings, rebuilds get its old copy, and Speedy removes those pages instead of rebuilding them.
- Visitors with their own pages. CloudFront can’t skip its cache by part of a cookie name, so logged-in visitors and visitors part-way through a multi-page form may get the public copy from CloudFront. Pages Speedy doesn’t cache are sent as
private, so CloudFront never keeps them. Use Ajax for multi-page forms, or a separate behaviour with caching off for paths like/account*.
Keeping it free
CloudFront includes 1,000 invalidation paths a month, then charges per path. Speedy:
- sends one path per changed page;
- when one clear has more than 30 paths (
wildcardThreshold), groups them by first folder:/news/a,/news/band/news/cbecome/news*; - if there are still too many, sends
/*, which counts as one path; - sends
/*for Clear all pages; - counts the paths used this month, shown on the utility page.
Failures
Invalidation errors, such as a wrong distribution ID, are shown on the utility page and in the log. Pages on your server are still cleared and rebuilt.