Home

Awesome

serverless-api-cloudfront

serverless npm version MIT licensed npm downloads

Automatically creates properly configured AWS CloudFront distribution that routes traffic to API Gateway.

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

:zap: Pros

Installation

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

Configuration

# add in your serverless.yml

plugins:
  - serverless-api-cloudfront

custom:
  apiCloudFront:
    domain: my-custom-domain.com
    certificate: 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
    minimumProtocolVersion: TLSv1

Notes

domain:
  - my-custom-domain.com
  - secondary-custom-domain.com
cookies:
  - FirstCookieName
  - SecondCookieName
headers: all
querystring: all
priceClass: PriceClass_All
minimumProtocolVersion: TLSv1

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:

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

Error troubleshooting