serverless-api-gateway-caching
Advanced tools
Comparing version 1.0.0-rc14 to 1.0.0-rc15
{ | ||
"name": "serverless-api-gateway-caching", | ||
"version": "1.0.0-rc14", | ||
"version": "1.0.0-rc15", | ||
"description": "A plugin for the serverless framework which helps with configuring caching for API Gateway endpoints.", | ||
@@ -5,0 +5,0 @@ "main": "src/apiGatewayCachingPlugin.js", |
@@ -31,3 +31,3 @@ # serverless-api-gateway-caching | ||
# Responses are cached based the 'pawId' path parameter and the 'Accept-Language' header | ||
# Responses are cached based on the 'pawId' path parameter and the 'Accept-Language' header | ||
get-cat-by-paw-id: | ||
@@ -48,1 +48,5 @@ handler: rest_api/cat/get/handler.handle | ||
``` | ||
## Limitations | ||
Currently not supported: | ||
- lambda functions with many http events |
@@ -20,3 +20,3 @@ 'use strict'; | ||
createSettings() { | ||
this.settings = new ApiGatewayCachingSettings(this.serverless); | ||
this.settings = new ApiGatewayCachingSettings(this.serverless, this.options); | ||
} | ||
@@ -23,0 +23,0 @@ |
@@ -21,3 +21,3 @@ const isEmpty = require('lodash.isempty'); | ||
class ApiGatewayCachingSettings { | ||
constructor(serverless) { | ||
constructor(serverless, options) { | ||
if (!get(serverless, "service.custom.apiGatewayCaching")) { | ||
@@ -28,2 +28,14 @@ this.cachingEnabled = false; | ||
this.cachingEnabled = serverless.service.custom.apiGatewayCaching.enabled; | ||
if (!this.cachingEnabled) { | ||
return; | ||
} | ||
if (options) { | ||
this.stage = options.stage || serverless.service.provider.stage; | ||
this.region = options.region || serverless.service.provider.region; | ||
} else { | ||
this.stage = serverless.service.provider.stage; | ||
this.region = serverless.service.provider.region; | ||
} | ||
this.cacheClusterSize = serverless.service.custom.apiGatewayCaching.clusterSize; | ||
@@ -30,0 +42,0 @@ this.cacheTtlInSeconds = serverless.service.custom.apiGatewayCaching.ttlInSeconds; |
@@ -23,4 +23,4 @@ const isEmpty = require('lodash.isempty'); | ||
const getApiGatewayMethodFor = (functionName, serverless) => { | ||
const fullFunctionName = `${serverless.service.service}-${serverless.service.custom.stage}-${functionName}`; | ||
const getApiGatewayMethodFor = (functionName, stage, serverless) => { | ||
const fullFunctionName = `${serverless.service.service}-${stage}-${functionName}`; | ||
const lambdaFunctionResource = getResourceForLambdaFunctionNamed(fullFunctionName, serverless); | ||
@@ -43,3 +43,3 @@ | ||
} | ||
const method = getApiGatewayMethodFor(endpointSettings.functionName, serverless); | ||
const method = getApiGatewayMethodFor(endpointSettings.functionName, settings.stage, serverless); | ||
if (!method.resource.Properties.Integration.CacheKeyParameters) { | ||
@@ -46,0 +46,0 @@ method.resource.Properties.Integration.CacheKeyParameters = []; |
const isEmpty = require('lodash.isempty'); | ||
const AWS = require('aws-sdk'); | ||
const getRestApiId = async serverless => { | ||
const stackName = serverless.providers.aws.naming.getStackName(serverless.service.provider.stage); | ||
const getRestApiId = async (settings, serverless) => { | ||
const stackName = serverless.providers.aws.naming.getStackName(settings.stage); | ||
let stack = await serverless.providers.aws.request('CloudFormation', 'describeStacks', { StackName: stackName }, | ||
serverless.service.provider.stage, | ||
serverless.service.provider.region | ||
settings.stage, | ||
settings.region | ||
); | ||
@@ -83,6 +83,6 @@ | ||
const updateStageCacheSettings = async (settings, serverless) => { | ||
let restApiId = await getRestApiId(serverless); | ||
let restApiId = await getRestApiId(settings, serverless); | ||
AWS.config.update({ | ||
region: serverless.service.custom.region, | ||
region: settings.region, | ||
}); | ||
@@ -98,3 +98,3 @@ | ||
restApiId, | ||
stageName: serverless.service.custom.stage, | ||
stageName: settings.stage, | ||
patchOperations: patchOps | ||
@@ -101,0 +101,0 @@ } |
12227
256
51