【问题标题】:How do I configure the routing rules in a cloudformation yaml?如何在 cloudformation yaml 中配置路由规则?
【发布时间】:2017-08-14 16:51:27
【问题描述】:

我正在尝试使用使用 cloudformation 的无服务器 yaml 为我的静态 s3 存储桶网站配置此网站路由规则。

<RoutingRules>
  <RoutingRule>
    <Condition>
      <KeyPrefixEquals/>
      <HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
    </Condition>
    <Redirect>
      <Protocol>https</Protocol>
      <HostName>foo.amazonaws.com</HostName>
      <ReplaceKeyPrefixWith>prod/photos/resize?key=</ReplaceKeyPrefixWith>
      <HttpRedirectCode>307</HttpRedirectCode>
    </Redirect>
  </RoutingRule>
</RoutingRules>

如何将其翻译成下面的 yaml?

resources:
  Resources:
    UploadBucket:
      Type: AWS::S3::Bucket
      Properties:
        BucketName: ${file(./serverless.env.yml):${opt:stage}.BucketName}
        AccessControl: PublicRead
        WebsiteConfiguration:
          IndexDocument: index.html
          RoutingRule: //What's the format that goes here?

【问题讨论】:

    标签: amazon-web-services amazon-s3 amazon-cloudformation


    【解决方案1】:

    RoutingRulesAmazon S3 Website Configuration Routing Rules Property 的列表。

    例如

    RoutingRules:
      - RedirectRule:
          HostName: foo.amazonaws.com
          HttpRedirectCode: "307"
          Protocol: https
          ReplaceKeyPrefixWith: prod/photos/resize?key=
        RoutingRuleCondition:
          HttpErrorCodeReturnedEquals: "404"
    

    【讨论】:

    • 应该像 HostName 这样的值在“引号”中,例如“foo.amazonaws.com”而不仅仅是纯文本?
    • 您不是必需的。这个答案更好地解释了它:: stackoverflow.com/questions/19109912/…
    【解决方案2】:

    如果有人感兴趣,这里是相同设置的 JSON 表示

    "WebsiteConfiguration" : {
     "IndexDocument": "index.html",
     "ErrorDocument": "error.html",
     "RoutingRules": [{
       "RedirectRule": {
          "HostName": {
            "foo.amazonaws.com"
          },
          "HttpRedirectCode": "307",
          "ReplaceKeyPrefixWith": "prod/photos/resize?key="
        },
        "RoutingRuleCondition": {
          "HttpErrorCodeReturnedEquals": "404"
        }
      }]
    }
    

    【讨论】:

      猜你喜欢
      • 2021-09-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      相关资源
      最近更新 更多