Amazon web services 部署后如何处理cloudfront缓存

Amazon web services 部署后如何处理cloudfront缓存,amazon-web-services,caching,amazon-s3,amazon-cloudfront,Amazon Web Services,Caching,Amazon S3,Amazon Cloudfront,我们在S3中有Angular2代码。我们通过Cloudfront访问它。 它很好用。 但是在部署到Angular2之后,我们希望每个代码都从Cloudfront失效。 部署后清除缓存的最佳方法是什么? 如何处理cloudfront缓存?您需要调用cloudfront API(或使用web控制台)使缓存无效 您可以在aws cli的帮助下执行部署和缓存失效 #!/bin/bash # enable cloudfront cli aws configure set preview.cloudfro

我们在S3中有Angular2代码。我们通过Cloudfront访问它。 它很好用。 但是在部署到Angular2之后,我们希望每个代码都从Cloudfront失效。 部署后清除缓存的最佳方法是什么?
如何处理cloudfront缓存?

您需要调用cloudfront API(或使用web控制台)使缓存无效

您可以在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 "/*"

请注意,这些解决方案的一个问题(正如我发现的那样)是CloudFront失效可能会在CodeDeploy完成对所有EC2实例的部署之前运行


一些因素是您的部署配置,以及您有多少EC2实例。我正在考虑向这种获取部署状态并在成功后失效的流程中添加一些检查

我意识到处理这一问题的最佳方法是使用由SNS事件触发的Lambda函数。SNS事件仅在部署成功时由CodeDeploy调用。因此,我只会在成功部署时使缓存无效。