Coder Social home page Coder Social logo

dseeker / serverless-api-cloudfront Goto Github PK

View Code? Open in Web Editor NEW

This project forked from droplr/serverless-api-cloudfront

0.0 1.0 0.0 72 KB

Serverless Plugin - CloudFront distribution in front of your API Gateway

License: MIT License

JavaScript 100.00%

serverless-api-cloudfront's Introduction

aws-serverless-api-cloudfront

This package is based on serverless-api-cloudfront

serverless npm version MIT licensed npm downloads

Automatically creates properly configured AWS CloudFront distribution that routes traffic to API Gateway as well as a Route53 A record to point to the distribution from a custom domain name.

Due to limitations of API Gateway Custom Domains, we realized that setting self-managed CloudFront distribution is much more powerful.

โšก Pros

  • Allows you to set-up a CloudFront distribution for your API Gateway
  • Sets up a Route 53 DNS entry for the CloudFront distribution
  • More CloudWatch statistics of API usage (like bandwidth metrics)
  • Real world access log - out of the box, API Gateway currently does not provide any kind of real "apache-like" access logs for your invocations
  • Web Application Firewall support - enable AWS WAF to protect your API from security threats

Installation

$ npm install --save-dev dseeker/serverless-api-cloudfront

Configuration

  • FullDomainName - This is REQUIRED and is used to determine the Domain name of the CloudFront Distribution as well register the Route53 A record. In addition, the hostname will be extracted from the full domain name and used to find the correct certificate if the certificate ARN is not explicitly provided.
  • All apiCloudFront configuration parameters are optional other than FullDomainName
  • First deployment may be quite long (e.g. 30 min) as Serverless is waiting for CloudFormation to deploy CloudFront distribution.
# add in your serverless.yml

plugins:
  - aws-serverless-api-cloudfront

custom:
  apiCloudFront:
    fullDomainName:  api.my-custom-domain.com
    certificate: (Determined from fullDomainName if not present) arn:aws:acm:us-east-1:000000000000:certificate/00000000-1111-2222-3333-444444444444
    waf: 00000000-0000-0000-0000-000000000000
    compress: true
    logging:
      bucket: my-bucket.s3.amazonaws.com
      prefix: my-prefix
    cookies: none
    headers:
      - x-api-key
    querystring:
      - page
      - per_page
    priceClass: PriceClass_100
    defaultTTL: 3600

Notes

  • cookies can be all (default), none or a list that lists the cookies to whitelist
cookies:
  - FirstCookieName
  - SecondCookieName
headers: all
  • querystring can be all (default), none or a list, in which case all querystring parameters are forwarded, but cache is based on the list:
querystring: all
  • priceClass can be PriceClass_All (default), PriceClass_100 or PriceClass_200:
priceClass: PriceClass_100 is the default
minimumProtocolVersion: TLSv1
  • [defaultTTL][default-ttl] '0' is default:
defaultTTL: '0'
  • [functionAssociations][function-associations] not configured by defailt
functionAssociations:
  - EventType: viewer-request
    LambdaFunctionARN: arn:aws:lambda:us-east-1:****:function:****

IAM Policy

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

More specifically this plugin needs the following policies attached:

  • cloudfront:CreateDistribution
  • cloudfront:GetDistribution
  • cloudfront:UpdateDistribution
  • cloudfront:DeleteDistribution
  • cloudfront:TagResource

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

Error troubleshooting

  • Make sure you have at least one http event otherwise you'll get The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template

serverless-api-cloudfront's People

Contributors

adambrgmn avatar danielmuller avatar dependabot[bot] avatar dseeker avatar eric-swann-q2 avatar gribnoysup avatar lepirlouit avatar necromos avatar orfin avatar oroce avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.