serverless / serverless-client-s3

A plugin to deploy front-end assets to S3 via the Serverless Framework
http://www.serverless.com
171 stars 61 forks source link

Enhancement: Manage Cloudfront distributions for client code #15

Open andreipopovici opened 8 years ago

andreipopovici commented 8 years ago

Hi there,

Back in the days of JAWS, there was an interesting plugin: https://github.com/boushley/awsm-cloudfront

Basically, it would set up a Cloudfront distribution with two origins, one for static client code on S3 and another with the serverless API Gateway endpoints (using a base-path, like /api/). It would then be trivial to redirect to the distribution URL via Route 53 or others.

This might be a job for a separate plugin that has serverless-client-s3 as a dependency and also sets up the serverless API part.

I thought I'd bring it up here :)

konrad-garus commented 8 years ago

This would be a very useful feature.

andreipopovici commented 8 years ago

One thing to consider in the implementation is how to handle cache invalidation. Cloudfront offers 1000 individual invalidations per month free, and the cost could skyrocket for say, a static site with many pages.

However, changing the S3 origin path is free. Thus, uploading to a hashed folder name on S3 on each deploy, then changing the origin path to that folder is faster and cheaper.

andrewluetgers commented 7 years ago

Could use Lambda@Edge to dynamically define a versioned path for assets. http://docs.aws.amazon.com/lambda/latest/dg/lambda-edge.html