Question:
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?
Answer:
You can do both deployment and cache invalidation with the help of aws-cli.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#!/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 "/*" |