serverless-application-model icon indicating copy to clipboard operation
serverless-application-model copied to clipboard

Is there any way to define the API Gateway cache TTL?

Open sgruenheit opened this issue 9 years ago • 13 comments

In the resource type AWS::Serverless::Api I'm able to enable the API Gateway caching using CacheClusterEnabled: true CacheClusterSize: "0.5"

I can't see any possibility to set the cache TTL anywhere - is there any way to do it? Unfortunately the cache is not working without that value and setting it manually is not an option.

Thanks in advance

sgruenheit avatar May 09 '17 07:05 sgruenheit

Interesting. Where do you usually specify the TTL with AWS::ApiGateway::Stage resource? In MethodSettings property? If so, yes, SAM should support it.

sanathkr avatar Jun 28 '17 08:06 sanathkr

Thank you for answer. Actually it seems to be defined in the MethodSetting of AWS::ApiGateway::Stage.

http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apitgateway-stage-methodsetting.html

That would actually mean, that it is needed to define it for every method separately (which is not so nice).

sgruenheit avatar Jun 28 '17 08:06 sgruenheit

Yeah, that's how the TTL is defined in API Gateway.

sanathkr avatar Jun 28 '17 19:06 sanathkr

Yes at least at API level. When using the AWS Console it is configured at stage level (and can be overwritten on method level). Any chance to add it?

api gateway

sgruenheit avatar Jun 28 '17 19:06 sgruenheit

Turns out you can do it with method settings by using */* for path/method combo - http://docs.aws.amazon.com/cli/latest/reference/apigateway/create-stage.html. So yes, we can enable a Stage-wide TTL setting.

All of the MethodSettings properties look useful to expose via SAM. How about we simply allow the entire MethodSettings object and you set it to whatever you like?

sanathkr avatar Jun 29 '17 16:06 sanathkr

That sounds great! And yes I agree with you, the other settings are useful too and could be added as well!

sgruenheit avatar Jun 30 '17 05:06 sgruenheit

How would I go about to add TTL to each method until Stage-wide TTL is implemented?

saratitan avatar Jul 08 '17 15:07 saratitan

@Sarceus you can't with AWS::Serverless::Api resource. You have to fallback to doing it yourself using AWS::ApiGateway::* resources

sanathkr avatar Jul 09 '17 01:07 sanathkr

Just wanted to agree that more control over stage cache and per-method cache settings (or just exposing MethodSettings in general) would be a big help in avoiding post-deployment scripts, change sets, or manual adjustment of API settings.

antaltshul avatar Jul 18 '17 19:07 antaltshul

The fact that this is missing is quite a big showstopper for a lot of implementations. You normally want to use the cache for API Gateway as it is cheap and effective way to increase your performance. I could not get the cache working without setting the TTL to anything. The default value should be 300 but I think SAM might be overriding it to 0 which effectively disables the cache. It almost rendered SAM useless for us. I almost consider it a bug and not a feature request.

StoyanIvanovI avatar Dec 20 '17 15:12 StoyanIvanovI

We created a parent task to track this. Please see #248 for updates.

Closing as duplicate of #248

jfuss avatar Jan 08 '18 20:01 jfuss

How to enable api gateway cache ttl using methodSettings ? I am using this in template yaml but it does not work, it is not enabling caching at method level. Any thing missing here. Please help.

      CacheClusterEnabled: true
      CacheClusterSize: "1.6"
      MethodSettings: 
         - ResourcePath: "/*"
           CachingEnabled: true
           CacheTtlInSeconds: 600 
           HttpMethod: "GET"

sjain2015 avatar Nov 21 '18 08:11 sjain2015

@sjain2015, try just "/" as the resource path:

MethodSettings:
  - ResourcePath: /
    CachingEnabled: true

etc.

mearns avatar May 29 '19 20:05 mearns