Serverless-application-model: Is there any way to define the API Gateway cache TTL?

Created on 9 May 2017  路  13Comments  路  Source: aws/serverless-application-model

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

typduplicate typfeature

Most helpful comment

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?

All 13 comments

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

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).

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

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

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?

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

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

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

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.

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.

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

Closing as duplicate of #248

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, try just "/" as the resource path:

MethodSettings:
  - ResourcePath: /
    CachingEnabled: true

etc.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willdady picture willdady  路  3Comments

restfulhead picture restfulhead  路  4Comments

feinstein picture feinstein  路  3Comments

charsleysa picture charsleysa  路  3Comments

polovi picture polovi  路  3Comments