Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/correct peer dep #47

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": false,
"jsxBracketSameLine": true
}
44 changes: 37 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
# Changelog

## [0.9.5] - 2019-02-21
## [0.0.6] - 2022-05-04

### Fixed

- serverless version of peerDependencies

### Updated

- Throw exception when the lambda parameter is not set.

## [0.0.5] - 2022-05-01

### Fixed

- add peerDependencies

### Updated

- README

## [0.0.2] - 2022-04-21

### Fixed

- OriginPath should be ''

### Fixed

- Support for serverless v3

## [0.0.1] - 2022-04-21

### Added
- .gitignore file [#23](https://github.com/Droplr/serverless-api-cloudfront/pull/23)
- MinimumProtocolVersion [#25](https://github.com/Droplr/serverless-api-cloudfront/pull/25)

- for lambda url

### Fixed
- Missing bound in dependencies [#24](https://github.com/Droplr/serverless-api-cloudfront/pull/24)
- PriceClass documentation [#14](https://github.com/Droplr/serverless-api-cloudfront/pull/14)
- Incorrect node version [#26](https://github.com/Droplr/serverless-api-cloudfront/pull/26)
- Headers documentation [#27](https://github.com/Droplr/serverless-api-cloudfront/pull/27)

- Support for serverless v3
67 changes: 35 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# serverless-api-cloudfront
# serverless-lambda-cloudfront

[![serverless](http://public.serverless.com/badges/v3.svg)](http://www.serverless.com)
[![npm version](https://badge.fury.io/js/serverless-api-cloudfront.svg)](https://badge.fury.io/js/serverless-api-cloudfront)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/Droplr/serverless-api-cloudfront/master/LICENSE)
[![npm downloads](https://img.shields.io/npm/dt/serverless-api-cloudfront.svg?style=flat)](https://www.npmjs.com/package/serverless-api-cloudfront)
[![npm version](https://badge.fury.io/js/serverless-lambda-cloudfront.svg)](https://badge.fury.io/js/serverless-lambda-cloudfront)
[![MIT licensed](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/serverless-lambda-cloudfront/master/LICENSE)
[![npm downloads](https://img.shields.io/npm/dt/serverless-lambda-cloudfront.svg?style=flat)](https://www.npmjs.com/package/serverless-lambda-cloudfront)

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.
to Lambda Url.

**:zap: Pros**

- Allows you to set-up custom domain for your API Gateway
- Enables CDN caching of resources - so you don't waste Lambda invocations or API Gateway traffic
- Allows you to set-up custom domain for your Lambda Url
- [Lambda Url](https://www.serverless.com/blog/aws-lambda-function-urls-with-serverless-framework)
- Enables CDN caching of resources - so you don't waste Lambda invocations
for serving static files (just set proper Cache-Control in API responses)
- Much more CloudWatch statistics of API usage (like bandwidth metrics)
- Real world [access log](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/AccessLogs.html) - out of the box, API Gateway currently does not provide any kind of real "apache-like" access logs for your invocations
Expand All @@ -22,27 +21,28 @@ Due to limitations of API Gateway Custom Domains, we realized that setting self-
## Installation

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

## Configuration

* All apiCloudFront configuration parameters are optional - e.g. don't provide ACM Certificate ARN
- All lambdaCloudFront configuration parameters are optional - e.g. don't provide ACM Certificate ARN
to use default CloudFront certificate (which works only for default cloudfront.net domain).
* This plugin **does not** set-up automatically Route53 for newly created CloudFront distribution.
- This plugin **does not** set-up automatically Route53 for newly created CloudFront distribution.
After creating CloudFront distribution, manually add Route53 ALIAS record pointing to your
CloudFront domain name.
* First deployment may be quite long (e.g. 10 min) as Serverless is waiting for
- First deployment may be quite long (e.g. 10 min) as Serverless is waiting for
CloudFormation to deploy CloudFront distribution.

```
# add in your serverless.yml

plugins:
- serverless-api-cloudfront
- serverless-lambda-cloudfront

custom:
apiCloudFront:
lambdaCloudFront:
lambda: myFunction
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
Expand All @@ -58,26 +58,35 @@ custom:
- per_page
priceClass: PriceClass_100
minimumProtocolVersion: TLSv1

...

functions:
myFunction:
url: true
...

```

### Notes

* `domain` can be list, so if you want to add more domains, instead string you list multiple ones:
- `domain` can be list, so if you want to add more domains, instead string you list multiple ones:

```
domain:
- my-custom-domain.com
- secondary-custom-domain.com
```

* `cookies` can be *all* (default), *none* or a list that lists the cookies to whitelist
- `cookies` can be _all_ (default), _none_ or a list that lists the cookies to whitelist

```
cookies:
- FirstCookieName
- SecondCookieName
```

* [`headers`][headers-default-cache] can be *all*, *none* (default) or a list of headers ([see CloudFront custom behaviour][headers-list]):
- [`headers`][headers-default-cache] can be _all_, _none_ (default) or a list of headers ([see CloudFront custom behaviour][headers-list]):

```
headers: all
Expand All @@ -86,44 +95,38 @@ headers: all
[headers-default-cache]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-distribution-defaultcachebehavior.html#cfn-cloudfront-distribution-defaultcachebehavior-forwardedvalues
[headers-list]: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/RequestAndResponseBehaviorCustomOrigin.html#request-custom-headers-behavior

* `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` 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`][price-class] can be `PriceClass_All` (default), `PriceClass_100` or `PriceClass_200`:

- [`priceClass`][price-class] can be `PriceClass_All` (default), `PriceClass_100` or `PriceClass_200`:

```
priceClass: PriceClass_All
```

[price-class]: https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_GetDistributionConfig.html#cloudfront-GetDistributionConfig-response-PriceClass

* [`minimumProtocolVersion`][minimum-protocol-version] can be `TLSv1` (default), `TLSv1_2016`, `TLSv1.1_2016`, `TLSv1.2_2018` or `SSLv3`:
- [`minimumProtocolVersion`][minimum-protocol-version] can be `TLSv1` (default), `TLSv1_2016`, `TLSv1.1_2016`, `TLSv1.2_2018` or `SSLv3`:

```
minimumProtocolVersion: TLSv1
```

[minimum-protocol-version]: https://docs.aws.amazon.com/cloudfront/latest/APIReference/API_ViewerCertificate.html#cloudfront-Type-ViewerCertificate-MinimumProtocolVersion


### 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`
- `cloudfront:CreateDistribution`
- `cloudfront:GetDistribution`
- `cloudfront:UpdateDistribution`
- `cloudfront:DeleteDistribution`
- `cloudfront:TagResource`

You can read more about IAM profiles and policies in the [Serverless documentation](https://serverless.com/framework/docs/providers/aws/guide/credentials#creating-aws-access-keys).

## 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```
Loading