【问题标题】:Cloudformation apigateway cache setup for proxy resource代理资源的 Cloudformation apigateway 缓存设置
【发布时间】:2020-10-19 08:07:25
【问题描述】:

有人可以提供有关如何在 cloudformation 模板中使用 greedy path sub-resource ('{proxy+}') 指定缓存策略的建议。

我已经通过 CloudFormation 使用 apigateway 设置了一个 REST API。网关配置了一个通用的cache policy on the stage deployment。但是,对于特定的贪婪路径子资源,我想指定自定义缓存策略。当路径名是标准字符串(例如“/~1abcde~1fghijk”)时,我能够通过模板成功实现这一点,但对于下面的 sn-p 的“{proxy+}”则不行。

  Stage:
    Type: AWS::ApiGateway::Stage
    Properties:
      RestApiId: xxxx
      StageName: xxxx
      Description: 'Api stage for deployment'
      DeploymentId: xxxx
      TracingEnabled: True
      CacheClusterEnabled: True
      CacheClusterSize: 0.5
      MethodSettings:
        - ResourcePath: "/~1abcde~1fghijk"
          HttpMethod: "*"
          CacheTtlInSeconds: 0
          CachingEnabled: false
        - ResourcePath: "/~1abcde~1{proxy+}"
          HttpMethod: "*"
          CacheTtlInSeconds: 0
          CachingEnabled: false

【问题讨论】:

  • 你能澄清什么问题吗?模板不部署?有什么错误吗?
  • 没有错误,模板部署正常。问题是策略没有生效,因为资源仍然从阶段继承而不是覆盖。
  • 如果你这样做,但使用控制台,它是否按预期工作?因此,问题是如何在 CFN 中复制它?
  • 正确。通过控制台覆盖时没有问题。
  • @Marcin 感谢您的帮助,已确定并解决了我的问题。

标签: amazon-web-services amazon-cloudformation aws-api-gateway api-gateway


【解决方案1】:

解决了这个问题。感谢 Marcin 的 cmets。

我可以在指定特定的 HttpMethod 时覆盖部署阶段策略。出于某种原因,与AWS Documentation 相反,对HttpMethod 使用通配符“*”会导致静默失败。新的cloudformation资源模板sn-p如下:

    - ResourcePath: "/~1abcde~1{proxy+}"
      HttpMethod: GET
      CacheTtlInSeconds: 0
      CachingEnabled: false

【讨论】:

    猜你喜欢
    • 2017-07-19
    • 1970-01-01
    • 2019-08-31
    • 2022-01-13
    • 2020-10-01
    • 2018-05-25
    • 2021-10-28
    • 2017-11-12
    • 2023-03-22
    相关资源
    最近更新 更多