The issue occurs when S3 metadata (e.g., Content-Type) is updated, but CloudFront continues serving cached content with outdated metadata, like application/x-mp4 instead of video/mp4. CloudFront serves the old cached version even after manual updates or running a cron job.
CloudFront caches both the content and metadata (like Content-Type) at its edge locations. Once cached, CloudFront will continue serving this stale data until:
a. Manually Invalidate CloudFront Cache
-> AWS Console Steps:
-> AWS CLI Example:
aws cloudfront create-invalidation \
--distribution-id YOUR_DISTRIBUTION_ID \
--paths "/path/to/video.mp4"
b. Use Proper Cache-Control Headers
Ensure S3 objects have correct Cache-Control headers to define how long objects should be cached by CloudFront. Example:
Cache-Control: max-age=60
c. Automate Invalidation in Cron Job
Update your cron job script to include CloudFront cache invalidation each time it updates metadata.