Dan Van Brunt
06/17/2021, 4:23 PMcache-control
settings to files uploaded by StaticSite?
The issue is when those cache control settings are very specific, like with gatsbyjs.
I can only seem to get it to work on FIRST upload if I use..
1. 3x deployments
2. order the deployments with deps
3. prune only on first deploy
However, on preceeding deploys, if you change a file name (or delete file) that impacts only say the 2nd deployment package, then you will have the old file as an orphan.
Would LOVE some ideas on how to resolve this limitation.
Other things I’ve half-baked-considered:
• running aws s3 cp bucket bucket
to retroactively update cache control settings.
◦ many challenges here…
◦ time consuming looping throw assets twice
◦ can’t be built into a Construct (unless rewriting the deploy construct) since it would need to have the target bucket already deployed/created.
• using programmatic CDK deploy and using execSync
to upload the assets AFTER CDK deploys.
Special Note:
It appears that aws cli's s3 sync
--delete option takes into account the whole directory of files and NOT just the ones the command is filtering on.
However, `s3deploy.BucketDeployment`’s prune option ONLY takes into account the filtered files. This is the crux of the issue. That and there seems to be no way to have 1x single deployment that handles multiple sources “and their associated cache control settings”.
Anyone with experience with this stuff with some ideas, please share. Cheers!Frank
Frank
Frank
StaticSite
uses CloudFront. With CloudFront, you can have multiple behaviors, and each behavior can have their own cache policy.Frank
const site = new StaticSite(this, "MyGatsbySite", { ... });
site.cfDistribution.addBehavior(
"/*.js",
new origins.S3Origin(site.s3Bucket),
{
cachePolicy: new cloudfront.CachePolicy(...),
...
}
);
Frank
Dan Van Brunt
06/17/2021, 8:26 PMcache-control
settings. Let me try and explain what I think the difference is:
CachePolicy: affects how the SERVER/DISTRO deals with caching
S3 cache-control: How the BROWSER caches the files.
No?Dan Van Brunt
06/17/2021, 8:29 PMFrank
Frank
Dan Van Brunt
06/17/2021, 8:32 PMDan Van Brunt
06/17/2021, 8:34 PMFrank
Dan Van Brunt
06/17/2021, 8:35 PMaws s3 sync /local bucket --delete
over on the CDK BucketDeploymentsDan Van Brunt
06/17/2021, 8:35 PMFrank
s3 sync
command help with?Frank
Frank
Frank
Dan Van Brunt
06/17/2021, 8:38 PMDan Van Brunt
06/17/2021, 8:39 PMFrank
Dan Van Brunt
06/17/2021, 8:43 PMDan Van Brunt
06/17/2021, 8:55 PMFrank
Frank
Frank
Frank
Frank
cacheControl
settings to different files. For example, don’t cache *.html
and cache *.css *.js
forever. Example here - https://docs.serverless-stack.com/constructs/StaticSite#configure-caching
• StaticSite
now does atomic deploys. Each deployment gets deployed to a new folder in S3 bucket. So no orphan files.
• You can specify a list of glob patterns, with the search and replace terms for each. Example here - https://docs.serverless-stack.com/constructs/StaticSite#replace-deployed-valuesFrank
Dan Van Brunt
06/21/2021, 5:48 PMDan Van Brunt
06/22/2021, 7:32 PM@aws-cdk/lambda-layer-awscli
? Does that layer work in TS as well? If so, thats amazing. I thought my only options were to use the AWS “SDK” but just inspecting your code it appears that the layer allows for “CLI” usage from within lambda.Frank
Frank
Frank
Dan Van Brunt
06/22/2021, 8:04 PMFrank