Expand description
AWS CloudFront invalidator for crate::cache_invalidate::PageCacheInvalidator.
Wires the per-page cache-invalidation hook to CloudFront’s CreateInvalidation API. After a CMS save, the public path is dropped from every edge POP in the distribution so the next request regenerates against the freshly-saved markup instead of the cached version.
§Usage
Behind the cache_cloudfront feature. The minimum config is
the distribution id; credentials come from the standard AWS
config chain (env vars, shared credentials file, IRSA / IMDS
when running on EKS/EC2, etc.):
use rustango_cms::cache_cloudfront::CloudFrontInvalidator;
// `from_env_distribution` resolves AWS credentials from the
// standard provider chain and builds the client. async because
// the SDK's config loader does an `imds` lookup on EC2/EKS.
let inv = CloudFrontInvalidator::from_env_distribution(
std::env::var("CLOUDFRONT_DISTRIBUTION_ID").unwrap(),
).await;
let router = rustango_cms::admin::router_with_invalidator(
tera.clone(),
std::sync::Arc::new(inv),
);§Permissions
The IAM principal (user / role) the SDK resolves to must carry:
cloudfront:CreateInvalidationscoped to the target distribution. The role-based assumption
flow (the role_arn field) is satisfied by setting
AWS_ROLE_ARN + AWS_WEB_IDENTITY_TOKEN_FILE in the
environment — the SDK picks them up automatically. Hand-rolled
AssumeRole is a follow-up; the env-driven flow covers EKS IRSA
- most CI runners.
§Failure mode
Logged through tracing at WARN; the calling admin handler
doesn’t propagate the error (cache invalidation is best-effort
by trait contract — a stale render is worse than a failed save).
Structs§
- Cloud
Front Invalidator - CloudFront-backed page-cache invalidator. Holds the resolved
SDK client + the target distribution id. Built via
Self::from_env_distribution(recommended) orSelf::with_clientfor tests / hand-rolled config.