smoketurner / serverless-cdn

Serverless project to deploy a CDN for hosting static assets in private S3 buckets

Home Page:https://github.com/smoketurner/sam-cdn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ARCHIVED - please use https://github.com/smoketurner/sam-cdn instead

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

About

Serverless project to deploy a CDN for hosting static assets in private S3 buckets

https://github.com/smoketurner/sam-cdn

License:MIT License


Languages

Language:JavaScript 100.0%