Skip to content

Commit 63e1896

Browse files
author
Diana Ionita
committed
Merge branch 'release/1.8.0'
2 parents e18439c + faa46a3 commit 63e1896

6 files changed

+90
-32
lines changed

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2022 Diana Ionita
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15+
PERFORMANCE OF THIS SOFTWARE.

README.md

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ functions:
227227
- http:
228228
path: /graphql
229229
method: post
230-
integration: lambda # you must use lambda integration (instead of the default proxy integration) for this to work
231230
caching:
232231
enabled: true
233232
cacheKeyParameters:
@@ -253,7 +252,6 @@ functions:
253252
- http:
254253
path: /graphql
255254
method: post
256-
integration: lambda # you must use lambda integration (instead of the default proxy integration) for this to work
257255
caching:
258256
enabled: true
259257
cacheKeyParameters:
@@ -289,6 +287,52 @@ custom:
289287
handleUnauthorizedRequests: Ignore
290288
```
291289

290+
### Example of configuring an API Gateway with endpoints scattered across multiple serverless projects
291+
292+
In the project hosting the main API Gateway deployment:
293+
294+
```yml
295+
plugins:
296+
- serverless-api-gateway-caching
297+
298+
custom:
299+
apiGatewayCaching:
300+
enabled: true # create an API cache
301+
ttlInSeconds: 0 # but don't cache responses by default (individual endpoints can override this)
302+
```
303+
304+
In a project that references that API Gateway:
305+
306+
```yml
307+
plugins:
308+
- serverless-api-gateway-caching
309+
310+
custom:
311+
apiGatewayCaching:
312+
enabled: true # enables caching for endpoints in this project (each endpoint must also set caching: enabled to true)
313+
apiGatewayIsShared: true # makes sure the settings on the Main API Gateway are not changed
314+
restApiId: ${cf:api-gateway-${self:provider.stage}.RestApiId}
315+
basePath: /animals
316+
317+
functions:
318+
# caching disabled, it must be explicitly enabled
319+
adoptCat:
320+
handler: adoptCat.handle
321+
events:
322+
- http:
323+
path: /cat/adoption
324+
method: post
325+
326+
getCats:
327+
handler: getCats.handle
328+
events:
329+
- http:
330+
path: /cats
331+
method: get
332+
caching:
333+
enabled: true # enables caching for this endpoint
334+
```
335+
292336
## Configuring caching settings for endpoints defined in CloudFormation
293337
You can use this feature to configure caching for endpoints which are defined in CloudFormation and not as serverless functions.
294338
If your `serverless.yml` contains, for example, a [HTTP Proxy](https://www.serverless.com/framework/docs/providers/aws/events/apigateway/#setting-an-http-proxy-on-api-gateway) like this:
@@ -396,7 +440,6 @@ functions:
396440
- http:
397441
path: /cats
398442
method: post
399-
integration: lambda # you must use lambda integration for this to work
400443
caching:
401444
enabled: true
402445
cacheKeyParameters:

package-lock.json

Lines changed: 18 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-api-gateway-caching",
3-
"version": "1.7.5",
3+
"version": "1.8.0",
44
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.",
55
"main": "src/apiGatewayCachingPlugin.js",
66
"scripts": {

src/pathParametersCache.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ const addPathParametersCacheConfig = (settings, serverless) => {
3030
let existingValue = method.Properties.RequestParameters[`method.${cacheKeyParameter.name}`];
3131
method.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = (existingValue == null || existingValue == undefined) ? {} : existingValue;
3232

33-
if (method.Properties.Integration.Type !== 'AWS_PROXY') {
33+
// in v1.8.0 "lambda" integration check was removed because setting cache key parameters seemed to work for both AWS_PROXY and AWS (lambda) integration
34+
// reconsider if this becomes an issue
35+
36+
// if (method.Properties.Integration.Type !== 'AWS_PROXY') {
3437
method.Properties.Integration.RequestParameters[`integration.${cacheKeyParameter.name}`] = `method.${cacheKeyParameter.name}`;
35-
}
38+
// }
3639

3740
method.Properties.Integration.CacheKeyParameters.push(`method.${cacheKeyParameter.name}`);
3841
} else {
@@ -44,9 +47,9 @@ const addPathParametersCacheConfig = (settings, serverless) => {
4447
) {
4548
method.Properties.RequestParameters[cacheKeyParameter.mappedFrom] = (existingValue == null || existingValue == undefined) ? {} : existingValue;
4649
}
47-
if (method.Properties.Integration.Type !== 'AWS_PROXY') {
50+
// if (method.Properties.Integration.Type !== 'AWS_PROXY') {
4851
method.Properties.Integration.RequestParameters[cacheKeyParameter.name] = cacheKeyParameter.mappedFrom;
49-
}
52+
// }
5053
method.Properties.Integration.CacheKeyParameters.push(cacheKeyParameter.name)
5154
}
5255
}

test/configuring-path-parameters.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Configuring path parameter caching', () => {
4141
});
4242
});
4343

44+
// in v1.8.0 "lambda" integration check was removed because setting cache key parameters seemed to work for both AWS_PROXY and AWS (lambda) integration
4445
describe('when one endpoint with lambda integration has cache key parameters', () => {
4546
let cacheKeyParameters, method, functionWithCachingName;
4647
before(() => {
@@ -70,10 +71,10 @@ describe('Configuring path parameter caching', () => {
7071
}
7172
});
7273

73-
it('should not set any integration request parameters', () => {
74+
it('should set integration request parameters', () => {
7475
for (let parameter of cacheKeyParameters) {
7576
expect(method.Properties.Integration.RequestParameters)
76-
.to.not.include({
77+
.to.include({
7778
[`integration.${parameter.name}`]: `method.${parameter.name}`
7879
});
7980
}

0 commit comments

Comments
 (0)