【问题标题】:How do you create an AWS Cloudfront Distribution that points to an S3 (static hosted) Website Endpoint using the SDK?如何使用 SDK 创建指向 S3(静态托管)网站终端节点的 AWS Cloudfront 分发?
【发布时间】:2017-04-04 12:39:13
【问题描述】:

我有一个配置为网站端点的 S3 存储桶来托管静态网页。

我想把 Cloudfront 放在前面。

我从 S3 存储桶的 “属性” :: “静态网站托管”中复制了 “端点”

格式为:“example.com.s3-website-us-east-1.amazonaws.com”

当我尝试使用 Aws SDK CloudFront 客户端创建_distribution 时,我收到此错误:

Aws::CloudFront::Errors::InvalidArgument 
The parameter Origin DomainName does not refer to a valid S3 bucket.

示例 Ruby 代码如下:

cloudfront = Aws::CloudFront::Client.new()
cloudfront.create_distribution({
  distribution_config: {
    ...
    origins: {
      quantity: 1,
      items: [{
        id: "Custom-example.com.s3-website-us-east-1.amazonaws.com",
        domain_name: "example.com.s3-website-us-east-1.amazonaws.com",
        s3_origin_config: {
          origin_access_identity: ""
        },
        origin_path: ""
      }]
    },
    ...
  }

})

我可以通过 GUI 和 CLI 创建具有相同“源域名”的分发版

aws cloudfront create-distribution \
  --origin-domain-name example.com.s3-website-us-east-1.amazonaws.com \
  --default-root-object index.html

【问题讨论】:

    标签: ruby amazon-web-services amazon-cloudfront aws-sdk-ruby


    【解决方案1】:

    静态托管在 S3 存储桶上的网站端点需要配置为“Origin Type”“custom_origin”NOT S3_Origin。您可以在 GUI 中分发的“起源”选项卡下看到这种情况。

    示例 Ruby 代码:

        distribution_config: {
        ...
          origins: {
            quantity: 1,
            items: [{
              id: "Custom-example.com.s3-website-us-east-1.amazonaws.com",
              domain_name: "example.com.s3-website-us-east-1.amazonaws.com",
              custom_origin_config: {
                http_port: 80, # required
                https_port: 443, # required
                origin_protocol_policy: "http-only", # required, accepts http-only, match-viewer, https-only
              },
            }]
         ...
         }
    

    【讨论】:

    • 非常感谢你 - 这几乎是不可能找到的......
    猜你喜欢
    • 2017-05-14
    • 2021-07-16
    • 2019-09-28
    • 2019-07-29
    • 2019-05-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-27
    • 2022-01-08
    相关资源
    最近更新 更多