【问题标题】:AWS::Serverless::Api - Cache Cluster set cache time to liveAWS::Serverless::Api - 缓存集群设置缓存生存时间
【发布时间】:2022-10-07 04:56:53
【问题描述】:

我使用 SAM 设置了一个带有 AWS::Serverless::Api 的 HTTP 代理。虽然我能够设置 CacheClusterEnabled 和 CacheClusterSize。我还没有找到一个属性来设置缓存数据的生存时间。我在哪里可以设置这个配置?

这是我的 templates.yml 文件:

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

这是创建的 API:

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

    标签: aws-api-gateway aws-sam aws-sam-cli


    【解决方案1】:

    任何对答案感兴趣的人。我发现我们可以使用https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-stage-methodsetting.html#cfn-apigateway-stage-methodsetting-datatraceenabled 配置这些属性。这是具有此配置的我的模板:

     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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-08
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多