【问题标题】:How to disable CloudFront caching in serverless.yml如何在 serverless.yml 中禁用 CloudFront 缓存
【发布时间】:2017-03-03 15:21:51
【问题描述】:

Serverless-1.0.0 允许部署 API 以通过 AWS API 网关with a custom domain 访问

问题:使用我的 serverless.yml,我需要禁用 CloudFront 的缓存(例如,通过为缓存标头设置一些零 TTL……还有其他方法吗?)

这可以在serverless.yml 或无服务器框架内完成吗?

【问题讨论】:

    标签: amazon-web-services aws-lambda serverless-framework


    【解决方案1】:

    您是否尝试过根据 Serverless 的参考 YML 在 provider 下定义 cachePolicy,然后通过函数的 CloudFront 事件链接 cachePolicy?直接来自无服务器框架示例 YML,如下所示:

    provider:
      cloudFront:
        myCachePolicy1: # used as a reference in function.events[].cloudfront.cachePolicy.name
          DefaultTTL: 60
          MinTTL: 30
          MaxTTL: 3600
          Comment: my brand new cloudfront cache policy # optional
          ParametersInCacheKeyAndForwardedToOrigin:
            CookiesConfig:
              CookieBehavior: whitelist # Possible values are 'none', 'whitelist', 'allExcept' and 'all'
              Cookies:
                - my-public-cookie
            EnableAcceptEncodingBrotli: true # optional
            EnableAcceptEncodingGzip: true
            HeadersConfig:
              HeadersBehavior: whitelist # Possible values are 'none' and 'whitelist'
              Headers:
                - authorization
                - content-type
            QueryStringsConfig:
              QueryStringBehavior: allExcept # Possible values are 'none', 'whitelist', 'allExcept' and 'all'
              QueryStrings:
                - not-cached-query-string
    
    functions:
      yourFunction:
        events:
          - cloudFront:
              eventType: viewer-response
              includeBody: true
              pathPattern: /docs*
              cachePolicy:
                # Note, you can use only one of name or id
                name: myCachePolicy1 # Refers to a Cache Policy defined in provider.cloudFront.cachePolicies
                id: 658327ea-f89d-4fab-a63d-7e88639e58f6 # Refers to any external Cache Policy id
              origin:
                DomainName: serverless.com
                OriginPath: /framework
                CustomOriginConfig:
                  OriginProtocolPolicy: match-viewer
    

    【讨论】:

    • 既然您听起来像是从文档中借用了此参考 YML,您能否引用源代码?
    猜你喜欢
    • 2018-05-03
    • 2019-03-13
    • 1970-01-01
    • 2020-07-16
    • 1970-01-01
    • 2015-11-30
    • 2015-11-18
    • 2018-02-21
    • 2018-07-23
    相关资源
    最近更新 更多