Add a content delivery network with AWS CloudFront
One of the most mature and powerful content delivery networks is AWS CloudFront. Read more on the official AWS docs.
- 🌾 Provision and Deploy
- ⚠️ Important implementation notes
- 🔎 Fingerprint and ensure cache invalidation
Given the following
@app my-site @cdn @static
arc deploy will create a CloudFront distribution for the S3 bucket website URL.
Likewise, the following
@app my-site @cdn @static @http get /api post /graphql
arc deploy will create a CloudFront distribution for the S3 website and the API Gateway routes defined by the
CloudFront support is implemented independently of CloudFormation because the deployment performance combining these services is unacceptably slow.
Unfortunately when CF distributions are deployed via CloudFormation they are updated every deployment and this can push the feedback cycle 15 to 20 minutes. For this reason Architect creates a CDN distribution if you have
@cdn in the
.arc asynchronously via the AWS SDK and when it is available you will see
cloudfront.com URLs printed into the console. Likewise, removing
@cdn from the distribution will mark it for deletion (which itself can take a long time).
Enable fingerprinting in
@app my-site @cdn @static fingerprint true
This ensures your application can be updated independently of long lived caches.