we have our Angular2 code in S3 .And we access it via Cloudfront. It works fine. But after a deployment to Angular2 , we want every code to be invalidated from Cloudfront. What are the best approaches for clearing cache after deployment? How to handle cloudfront caching?
You can do both deployment and cache invalidation with the help of aws-cli.
#!/bin/bash
# enable cloudfront cli
aws configure set preview.cloudfront true
# deploy angular bundles
aws s3 sync $LOCAL s3://$S3_BUCKET \
--region=eu-central-1 \
--cache-control max-age=$CACHE_TIME
# invalidate cache in cloudfront
aws cloudfront create-invalidation \
--distribution-id $CLOUDFRONT_DISTRO_ID \
--paths "/*"
You will need to call the CloudFront API (or use the web console) to invalidate the cache. Here is the documentation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With