Skip to content
Serverless project to deploy a CDN for hosting static assets in private S3 buckets
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
.vscode
__tests__
dist
functions
resources
stages
.editorconfig
.eslintignore
.eslintrc
.gitattributes
.gitignore
.prettierignore
.prettierrc
CODE_OF_CONDUCT.md
LICENSE
README.md
SECURITY.md
jest-config.json
package-lock.json
package.json
serverless.yml
webpack.config.js

README.md

serverless-cdn

serverless MIT licensed build status

Serverless project that deploys a content delivery network (CDN) using AWS CloudFront for static assets hosted in a private S3 bucket.

This project creates the following resources:

  • AWS::CertificateManager::Certificate - *.<domain> SSL certificate
  • AWS::CloudFront::Distribution - [http|https]://<domain> distribution
  • AWS::CloudFront::Distribution - [http|https]://www.<domain> redirect distribution
  • AWS::CloudFront::CloudFrontOriginAccessIdentity
  • AWS::Route53::RecordSet - <domain> IPv4 DNS entry
  • AWS::Route53::RecordSet - <domain> IPv6 DNS entry
  • AWS::Route53::RecordSet - www.<domain> IPv4 DNS entry
  • AWS::Route53::RecordSet - www.<domain> IPv6 DNS entry
  • AWS::S3::Bucket - private access log bucket
  • AWS::S3::Bucket - private static asset bucket
  • AWS::S3::Bucket - private bucket to redirect requests to https://<domain>
  • AWS::S3::BucketPolicy - only allow CloudFront to access static asset bucket
  • AWS::Lambda::Function - Lambda@Edge function for single page applications to redirect requests to /index.html
  • AWS::Lambda::Function - Lambda@Edge function to add various web security HTTP response headers

Installation

git clone https://github.com/smoketurner/serverless-cdn.git
cd serverless-cdn
npm install

Run Tests

npm test

Deploy

npm run deploy
npm run client-deploy # deploy sample hello world from dist folder

You can either put your static assets into the dist folder and run npm run client-deploy to upload them to the S3 bucket, or upload files directly to the <domain> S3 bucket. Route53 and CloudFront will take care of any redirections and content serving for you.

Removal

npm run remove

References

You can’t perform that action at this time.