Search code examples
aws-api-gatewayaws-samaws-sam-cli

AWS::Serverless::Api - Cache Cluster set cache time to live


I have set a HTTP proxy with AWS::Serverless::Api using SAM. Although I was able to set CacheClusterEnabled and CacheClusterSize. I have not found a property to set the time to live of cache data. Where can I set this config?

Here is my templates.yml file:

Resources:


ProxyApi:
    Type: AWS::Serverless::Api
    Properties:
      CacheClusterEnabled: !FindInMap [EnvMap, !Ref Env, cacheClusterEnabled]
      CacheClusterSize: !FindInMap [EnvMap, !Ref Env, cacheClusterSize]
      Name: !Join [ '-', [!Ref Env, 'lead-generation-proxy'] ]
      StageName: !Ref Env
      DefinitionBody:
        Fn::Transform:
          Name: AWS::Include
          Parameters:
            Location: openapi/proxy.yml

And here is the API created:

openapi: 3.0.1
info:
  version: 1.0.0
paths:
  "/{proxy+}":
    x-amazon-apigateway-any-method:
      parameters:
      - name: proxy
        in: path
        required: true
        schema:
          type: string
      responses: {}
      x-amazon-apigateway-integration:
        responses:
          default:
            statusCode: '200'
        requestParameters:
          integration.request.path.proxy: method.request.path.proxy
        uri: 
          Fn::FindInMap : [EnvMap, Ref: Env, proxyUrl]
        passthroughBehavior: when_no_match
        httpMethod: ANY
        type: http_proxy

Solution

  • Anyone interested in the answer. I have found that we could configure these attributes with https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html#cfn-apigateway-stage-methodsetting-datatraceenabled. Here is my template with this configuration:

     ProxyApi:
        Type: AWS::Serverless::Api
        Properties:
          Name: !Join ["-", [!Ref Env, "lead-generation-proxy"]]
          StageName: !Ref Env
          TracingEnabled: !FindInMap [EnvMap, !Ref Env, tracingEnabled]
          CacheClusterEnabled: !FindInMap [EnvMap, !Ref Env, cacheClusterEnabled]
          CacheClusterSize: !FindInMap [EnvMap, !Ref Env, cacheClusterSize]
          MethodSettings:
            - HttpMethod: '*'
              ResourcePath: '/*'
              LoggingLevel: INFO
              CacheTtlInSeconds: 400
              CachingEnabled: !FindInMap [EnvMap, !Ref Env, cacheClusterEnabled]
              DataTraceEnabled: !FindInMap [EnvMap, !Ref Env, cacheClusterEnabled]
              MetricsEnabled: !FindInMap [EnvMap, !Ref Env, cacheClusterEnabled]
          DefinitionBody:
            Fn::Transform:
              Name: AWS::Include
              Parameters:
                Location: openapi/proxy.yml