[RFC] Static Website #5
Replies: 8 comments 39 replies
-
I wonder could it also handle wiping the bucket content. E.g. for For good reason S3 doesn't make it easy to empty a bucket but for some application configs it'd be completely legitimate to have this as part of the framework. |
Beta Was this translation helpful? Give feedback.
-
Also whilst you're mentioning Lambda@Edge, worth noting that you can also do that for static site "neat" URLs, e.g. you have a directory structure like
So you want |
Beta Was this translation helpful? Give feedback.
-
And just a thought but this feature should also work for static assets of a dynamic website I think... |
Beta Was this translation helpful? Give feedback.
-
One common use case for static websites is redirecting www to non-www addresses or viceversa. With a web server is the easiest thing in the world but with aws-static-website-stack is a very complex task. |
Beta Was this translation helpful? Give feedback.
-
About Security topic, adding default Security headers is a must have on this component. A set of default security headers could be a nice feature. Implementation using Lambda@Edge. Something like: static-websites:
landing:
path: 'public/landing'
securityHeaders: yes or (adding additional headers) static-websites:
landing:
path: 'public/landing'
securityHeaders:
default: yes
'X-XSS-Protection': '1; mode=block'
... |
Beta Was this translation helpful? Give feedback.
-
Maybe would be useful to enable brotli compression as well? |
Beta Was this translation helpful? Give feedback.
-
Out of curiosity, do you plan to support NextJS to the |
Beta Was this translation helpful? Give feedback.
-
Would be useful to let protect a static website with some kind of auth system. It would be great to provide staging versions of a website not public available. Maybe with Cloudfront function could be achieved something like basic authentication with username/password credentials? |
Beta Was this translation helpful? Give feedback.
-
The goal of this discussion is to get feedback on the "Static Website" component.
If you are new to Lift, a quick intro: it's a Serverless plugin that can be installed via npm and enabled in any
serverless.yml
file.Here is what we are planning so far.
Use case
Deploying static websites and single-page applications, for example React, VueJS or Angular apps.
Quick start
The example above will create an S3 bucket to host the static website, and set up the CloudFront CDN.
Note: this component takes about 5 minutes to deploy the first time.
In the first version, the website will be deployed manually to S3 using the AWS CLI:
In the future, deployment will happen automatically during
serverless deploy
, including CDN cache invalidation.How it works
The component will deploy:
Cache invalidation
Quick intro on how caching with CloudFront+S3 works:
Cache-Control: max-age=3600
in S3 (on each object): CloudFront + browsers will cache for 1 hour.Cache-Control: max-age=60
andCache-Control: s-maxage=3600
in S3 (on each object): browsers will cache for 1 minute (max-age) and CloudFront for 1 hour (s-maxage).Here are the use cases we plan on supporting:
I want a simple solution (no versioning) with edge caching.
Lift deploys without
Cache-Control
. CloudFront will cache, but not browsers. On deployment, Lift creates a CloudFront invalidation that clears the CloudFront cache.After the deployment, every new page load should get the latest version.
If a SPA was loaded in a browser before the deployment, every new asset loaded will be the new version.
I want the most aggressive caching.
In that scenario, website assets must contain a version number or hash in their filename (for example in React).
Lift deploys with
Cache-Control=3600
on all files except HTML. CloudFront will cache everything, browsers will cache everything except HTML files.Why not HTML? So that browsers always reload the latest HTML version that points to the latest filenames.
On deployment, Lift uploads the new files and creates a CloudFront invalidation which clears the CloudFront cache.
New page loads will receive the latest HTML files, pointing to the latest assets versions.
If a SPA was loaded in a browser before the deployment, it will keep trying to load old asset versions. This is why older versions are kept for 1 day in the S3 bucket. Lift clears old asset versions after 1 day.
Configuration reference
Custom domain
The configuration above will activate the custom domain mywebsite.com on CloudFront, using the provided HTTPS certificate.
The certificate must be registered in ACM in the
us-east-1
region before deploying.After deploying, a CloudFront domain will be generated. Create a CNAME DNS entry for your domain that points to that
xxx.cloudfront.net
domain.Browser caching
See the previous section about "Cache invalidation" for more details.
Security
Ideally, we want some security headers to be present in responses.
How can we implement that? Lambda@Edge? → heavy solution
Feedback is welcome, just post a reply to this discussion 🙏
Beta Was this translation helpful? Give feedback.
All reactions