Deploy Multi-Language Static HTML on CDN.
With Serverless Framework and AWS CloudFront. Delete Cache on redeploying and force redirect according to browser language
Repository for this medium article: Deploy Multi-Language Static HTML on CDN
Please read the article if you have any questions
With the rise of Single Page Application (SPA), the use of a Content Delivery Network (CDN) is more than recommended. It allows us to have fast and reliable static hosting with easy HTTPS set up around the world. I love CloudFront, but I was always frustrated with 2 things, that I can do with .htaccess or Nginx configuration:
- When I deploy a new version, I want it accessible immediately (clean server and browser cache)
- If browser it's in French, I want to redirect the user to /fr/index.html (for example)
- Automatic S3 Bucket set-up (all object private)
- Automatic Cloudfront set-up with policy access to the bucket
- Set up of AWS lambda with CloudFront Egde
- Redirect user according to browser language
- Copy the file to S3 Bucket
- Clean S3 Object Cache when redeploy
- Invalidate CDN Distribution when redeploy
- AWS S3 To Store the files for our website (html, css, js)
- AWS CloudFront For delivered our website on a CDN
- Serverless To help us deploying our infrastructure
- Serverless CLoudFront Lambda Edge To associate a Lambda function with CloudFront Edge
Install and follow instructions to setup serverless with AWS
Install the AWS CLI
Then Launch
git clone https://github.com/vdelacou/iblis-deploy-static
cd iblis-deploy-static
chmod +x deploy.sh
./deploy.sh
You can replace the content of the src folder with your site (HTML, CSS, JS) and also rename the project in serverless.yml (don't forget to change the lambda function languageRedirectCloudFront.js according to your need)
We add the bitbucket-pipelines.yml
file for you to use the bitbucket pipleines out of the box.
- Fork this repository to your own GitHub account and then clone it to your local device
- Make the necessary changes and ensure that the tests are passing
- Send a pull request
- None for the moment
Please, refer to LICENSE file