getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
912 stars 109 forks source link

Control how the CloudFront cache is invalidated #369

Open Nyholm opened 9 months ago

Nyholm commented 9 months ago

Start from the Use-case

I am running a single page react app. I have 10 different JS files (chunks) after I build my app.

It is normal that a user request 3-5 js files while they are using a part of the application. When they browse to another part they will download more files.

There is an issue if I decide to deploy a new version. Then the additional files are removed from the S3 and CDN. Now when the user asks for the additional files they get a 404.

I suggest to allow us to keep some files on S3 or CloudFront. Of course I would be open for alternative solutions

Example Config

No response

Implementation Idea

No response

mnapoli commented 9 months ago

I wonder if we could (and if S3 allows it), instead of deleting "obsolete" files, set them to expire (be deleted) after 1 day 🤔 I haven't researched that at all but that would be a solution that we could apply by default for everyone?

jaulz commented 3 weeks ago

Probably related to https://github.com/getlift/lift/issues/398

jaulz commented 3 weeks ago

@mnapoli yep, I was researching on the very same right now. I wonder if we could tag all obsolete files and then use a lifecycle rule to delete these tagged files after a day. The question is whether there is an efficient way to compare and add those tags. Maybe we can create a similar function s3SoftDelete? https://github.com/getlift/lift/blob/0d56286371e98fa921a88635a0b98cd3404eb488/src/utils/s3-sync.ts#L155

mnapoli commented 3 weeks ago

Why not, as long as it works