All Projects → serverless-components → aws-cloudfront

serverless-components / aws-cloudfront

Licence: other
Deploy an AWS CloudFront distribution for the provided origins using Serverless Components

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to aws-cloudfront

awesome-serverless-framework
Serverless Framework 开发资源汇总 🚀
Stars: ✭ 120 (+445.45%)
Mutual labels:  serverless-framework, serverless-components
ShareX-CDN
Basic image, text & file uploader CDN for ShareX
Stars: ✭ 22 (+0%)
Mutual labels:  cdn
pacman.store
Pacman Mirror via IPFS for ArchLinux, Endeavouros and Manjaro
Stars: ✭ 65 (+195.45%)
Mutual labels:  cdn
azure-cdn-ips
List of Azure CDN IP Addresses
Stars: ✭ 14 (-36.36%)
Mutual labels:  cdn
uploadcare-rails
Rails wrapper for Uploadcare
Stars: ✭ 48 (+118.18%)
Mutual labels:  cdn
async-script-loader
Asynchronous script loading for SPAs
Stars: ✭ 15 (-31.82%)
Mutual labels:  cdn
twitter
A serverless social network that's under development with some cool stuff, such as Serverless Framework, AppSync, GraphQL, Lambda, DynamoDB, Cognito, Kinesis Firehose, and Algolia ☁️
Stars: ✭ 29 (+31.82%)
Mutual labels:  serverless-framework
serverless-rack
Serverless plugin to deploy Ruby Rack applications (Sinatra/Rails/Padrino/Cuba etc.) and bundle gems
Stars: ✭ 58 (+163.64%)
Mutual labels:  serverless-framework
speed-tests
Code for comparing CDN speeds!
Stars: ✭ 22 (+0%)
Mutual labels:  cdn
serverless-tencent-scf
Add support for Tencent Cloud's serverless infrastructure to the Serverless Framework via this plugin
Stars: ✭ 53 (+140.91%)
Mutual labels:  serverless-framework
webneko-blog
✍️ Technical Blog written by @jiyuujin
Stars: ✭ 14 (-36.36%)
Mutual labels:  aws-cloudfront
AutoChange12306CDN
一个自动切换12306 CDN的代理,只需设置浏览器的代理为此软件监听端口,每次查询请求都会更换CDN,达到快速刷票的目的。
Stars: ✭ 35 (+59.09%)
Mutual labels:  cdn
Thunderstore
Thunderstore is a mod database and API for downloading mods. Thunderstore Discord: https://discord.gg/UWpWhjZken
Stars: ✭ 45 (+104.55%)
Mutual labels:  cdn
nocdn
Self-hosted alternative to CDNs.
Stars: ✭ 37 (+68.18%)
Mutual labels:  cdn
wrender
Image compression and transformation reverse-proxy for Express apps
Stars: ✭ 14 (-36.36%)
Mutual labels:  cdn
boilerplate-googlecloudfunctions-nodejs
A Serverless Framework Boilerplate for Google Cloud Functions support in Node.js
Stars: ✭ 15 (-31.82%)
Mutual labels:  serverless-framework
cdn
Simple and fast property-based configuration library for JVM apps, similar to JSON5 standard, also with JSON & YAML-like targets 🧾
Stars: ✭ 33 (+50%)
Mutual labels:  cdn
api-server
📡 API server for api.cdnjs.com - The #1 free and open source CDN built to make life easier for developers.
Stars: ✭ 48 (+118.18%)
Mutual labels:  cdn
EdgeAdmin
CDN & WAF集群管理系统。
Stars: ✭ 199 (+804.55%)
Mutual labels:  cdn
backend
Easily host entire web applications on a single AWS Lambda function using Serverless Components
Stars: ✭ 16 (-27.27%)
Mutual labels:  serverless-components

aws-cloudfront

 

Deploy an AWS CloudFront distribution for the provided origins using Serverless Components.

 

  1. Install
  2. Create
  3. Configure
  4. Deploy

 

1. Install

$ npm install -g serverless

2. Create

$ mkdir cdn
$ cd cdn

the directory should look something like this:

|- serverless.yml
|- .env      # your AWS api keys

# .env
AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX

3. Configure

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    region: us-east-1
    enabled: true # optional
    comment: 'My distribution' # optional
    defaults: # optional
      ttl: 15
      allowedHttpMethods: ['HEAD', 'GET']
      forward: # optional
        # array of header names, 'none' or 'all'
        headers: ['Accept', 'Accept-Language']
        # array of cookie names, 'none' or 'all'
        cookies: ['my-cookie]
        queryString: true
        queryStringCacheKeys: ['queryKey']
      viewerProtocolPolicy: 'https-only' # optional
      smoothStreaming: true # optional
      compress: true # optional
      fieldLevelEncryptionId: '123' # optional
      lambda@edge: # added to cloudfront default cache behavior
        viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version
    origins:
      - https://my-bucket.s3.amazonaws.com

Custom cache behavior

Custom cache behaviors support the same config parameters as the default cache behavior (see the example above).

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - url: https://my-assets.com
        pathPatterns:
          /static/images: # route any /static/images requests to https://my-assets.com
            ttl: 10
            allowedHttpMethods: ['GET', 'HEAD'] # optional
            forward: # optional
              headers: 'all' 
              cookies: ['auth-token']
              queryString: true
            compress: false # optional
            # ...

Lambda@Edge

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - url: https://sampleorigin.com
        pathPatterns:
          /sample/path:
            ttl: 10
            lambda@edge:
              viewer-request: arn:aws:lambda:us-east-1:123:function:myFunc:version # lambda ARN including version

Private S3 Content

To restrict access to content that you serve from S3 you can mark as private your S3 origins:

# serverless.yml

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - url: https://my-private-bucket.s3.amazonaws.com
        private: true

A bucket policy will be added that grants CloudFront with access to the bucket objects. Note that it doesn't remove any existing permissions on the bucket. If users currently have permission to access the files in your bucket using Amazon S3 URLs you will need to manually remove those.

This is documented in more detail here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-restricting-access-to-s3.html

4. Deploy

$ serverless

 

New to Components?

Checkout the Serverless Components repo for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].