DianaIonita/serverless-api-gateway-caching

cacheKeyParameters are always required as of 1.10.3

Closed this issue · 0 comments

Changes made in the latest 1.10.3 release have made it no longer possible to have optional request parameters on cacheKeyParameters. This breaks configurations from 1.10.2 and earlier that list optional parameters in cacheKeyParameters.

This bug was caused by #132 but never addressed.


From the AWS docs linked above:

"The value associated with the key is a Boolean flag indicating whether the parameter is required (true) or optional (false). The method request parameter names defined here are available in Integration to be mapped to integration request parameters or templates."

As this PR changed the default value to true, doesnt this mean that optional parameters I want to add to the cacheKeyParameters block are now always going to be required?

I am seeing in my lambda functions, parameters which were previously not required are now required.

You make a valid point and I am not entirely sure how it was dealt before, but I tried out an additional flag required and this is how it worked out.

# serverless.yml
cors: true
caching:
  enabled: true
  cacheKeyParameters:
    - name: request.querystring.required # Final value in API GW: True
      required: true
    - name: request.querystring.notrequired # Final value in API GW:  False
      required: false
    - name: request.querystring.letssee # Final value in API GW:  False
// src/cacheKeyParameters.js
const isRequired = cacheKeyParameter.required || false;
...
method.Properties.RequestParameters[`method.${cacheKeyParameter.name}`] = (existingValue == null || existingValue == undefined) ? isRequired : existingValue;
// cloudformation-stack.json
"ApiGatewayMethodAnotherGet": {
  "Type": "AWS::ApiGateway::Method",
  "Properties": {
    "HttpMethod": "GET",
    "RequestParameters": {
      "method.request.querystring.required": true,
      "method.request.querystring.notrequired": false,
      "method.request.querystring.letssee": false
  },
}

Originally posted by @geetchoubey in #132 (comment)