Socket
Socket
Sign inDemoInstall

serverless-with-cloudfront

Package Overview
Dependencies
10
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    serverless-with-cloudfront

CloudFront distribution in front of your http api gateway


Version published
Weekly downloads
12
decreased by-63.64%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

serverless-with-cloudfront

CircleCI serverless npm version MIT licensed npm downloads

A try to extend the project: https://github.com/Droplr/serverless-api-cloudfront

Automatically properly configured AWS CloudFront distribution that routes traffic to follow resource.

Automatically config custom domain and create Route 53 records

Installation

$ npm install --save-dev serverless-with-cloudfront

OR

$ yarn add -D serverless-with-cloudfront

Usage

Samples

A HTTP api gateway sample

Add to plugins section

plugins:
  - serverless-with-cloudfront

Add to custom section

custom:
  withCloudFront:
    type: http # for HTTP Api Gateway
  ...
# The `service` block is the name of the service
service: sample

frameworkVersion: '3'

plugins:
  - serverless-with-cloudfront

# The `provider` block defines where your service will be deployed
provider:
  name: aws
  runtime: nodejs12.x
  region: ap-northeast-1

custom:
  withCloudFront:
    type: http # for HTTP Api Gateway
    # hostedZoneId: 11223344
    # domain: my-custom-domain.com
    # certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
    headers:
      - Accept
      - Accept-Encoding
      - Accept-Language
      - Authorization
    # cookies: 'all'
    # querystring: 'all'
    # waf: 00000000-0000-0000-0000-000000000000
    # compress: true
    # minimumProtocolVersion: 'protocol version'
    # priceClass: 'PriceClass_All'
    # logging:
    #   bucket: my-bucket.s3.amazonaws.com
    #   prefix: my-prefix

# The `functions` block defines what code to deploy
functions:
  helloWorld:
    handler: handler.helloWorld
    # The `events` block defines how to trigger the handler.helloWorld code
    events:
      - httpApi: '*'

A REST api gateway sample

A Lambda Url sample

lambda must be set to the same name of target function

function must set url property

custom:
  withCloudFront:
    type: lambda
    lambda: helloWorld
  ...

functions:
  helloWorld:
    url: true
    ...

Configuration

fieldmustdefault-
type*-http
rest
lambda
lambdaIf the type is lambda, this field must be set to the target function name
hostedZoneIdThe Route 53 Hosted zone ID
domainThe custom domain name
certificateThe certificate of custom domain name
headers[]The headers that include in the cache key
cookiesallThe cookies that include in the cache key ( all, none or a whitelist)
queryStringallThe query strings that include in the cache key all, none or a whitelist)
wafThe id of WAF
compressfalseThe auto compress option: true | false
minimumProtocolVersionTLSv1TLSv1 | TLSv1_2016 | TLSv1.1_2016 | TLSv1.2_2018 | SSLv3
priceClassPriceClass_AllPriceClass_All | PriceClass_100 | PriceClass_200
loggingBucket and prefix settings for saving access logs

Notes

  • If domain is set, certificate also needs to be set
domain: my-custom-domain.com
certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
  • If hostedZoneId is set, domain (and certificate) also needs to be set
hostedZoneId: 11223344
domain: my-custom-domain.com
certificate: arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
headers:
  - Accept
  - Accept-Encoding
  - Accept-Language
  - Authorization

IAM Policy

In order to make this plugin work as expected a few additional IAM Policies might be needed on your AWS profile.

  • cloudfront:...
  • route53:...

You can read more about IAM profiles and policies in the Serverless documentation.

License

MIT

Keywords

FAQs

Last updated on 26 Aug 2022

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc