serverless-with-cloudfront
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
Add to plugins
section
plugins:
- serverless-with-cloudfront
Add to custom
section
custom:
withCloudFront:
type: http
...
service: sample
frameworkVersion: '3'
plugins:
- serverless-with-cloudfront
provider:
name: aws
runtime: nodejs12.x
region: ap-northeast-1
custom:
withCloudFront:
type: http
headers:
- Accept
- Accept-Encoding
- Accept-Language
- Authorization
functions:
helloWorld:
handler: handler.helloWorld
events:
- httpApi: '*'
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
field | must | default | - |
---|
type | * | - | http |
| | | rest |
| | | lambda |
lambda | △ | | If the type is lambda , this field must be set to the target function name |
hostedZoneId | | | The Route 53 Hosted zone ID |
domain | | | The custom domain name |
certificate | | | The certificate of custom domain name |
headers | | [] | The headers that include in the cache key |
cookies | | all | The cookies that include in the cache key ( all , none or a whitelist) |
queryString | | all | The query strings that include in the cache key all , none or a whitelist) |
waf | | | The id of WAF |
compress | | false | The auto compress option: true | false |
minimumProtocolVersion | | TLSv1 | TLSv1 | TLSv1_2016 | TLSv1.1_2016 | TLSv1.2_2018 | SSLv3 |
priceClass | | PriceClass_All | PriceClass_All | PriceClass_100 | PriceClass_200 |
logging | | | Bucket 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