I've been having issues with my React deployments to AWS S3 while using Cloudfront due to browsers caching and attempting to load chunks that were unavailable after using CDK Bucket Deployment.
I had been using prune: true
to clean up the bucket and this was causing all previous chunks to be deleted. However, the reality is we want to support N number of older chunks, just in case, and provide a mechanism for alerting the user that a new version is available (not part of this construct).
import { Bucket } from '@aws-cdk/aws-s3';
import { BucketDeployment, Source } from '@aws-cdk/aws-s3-deployment';
...
...
const bucket = new Bucket(this, 'SourceBucket');
const now = new Date().getTime();
const bucketDeployment = new BucketDeployment(this, 'deploy-spa', {
sources: [Source.asset('path/to/assets')],
destinationBucket: bucket,
metadata: { deployed: now.toString() },
prune: false
});
new BucketDeploymentExpirator(this, 'expirator', {
bucketDeployment: bucketDeployment, // need this to add cfn depends on
sourceBucket: bucket
})
I will attempt to align the major and minor version of this package with [AWS CDK], but always check the release descriptions for compatibility.