我试图首次使用CloudFormation来配置使用S3存储桶作为其源的CloudFront发行版。

但是,运行模板时,我收到错误One or more of your origins do not exist。我以为它是由于错误配置了原始域名而引起的,但是无法找到有效的配置。

我目前有以下模板:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Resources": {
    "AssetBucket": {
      "Type": "AWS::S3::Bucket",
      "Properties": {
        "BucketName": "cdn-assets",
        "AccessControl": "PublicRead",
        "CorsConfiguration": {
          "CorsRules": [
            {
              "AllowedHeaders": [
                "*"
              ],
              "AllowedMethods": [
                "GET"
              ],
              "AllowedOrigins": [
                "*"
              ],
              "Id": "OpenCors",
              "MaxAge": "3600"
            }
          ]
        }
      }
    },
    "AssetCDN": {
      "Type": "AWS::CloudFront::Distribution",
      "Properties": {
        "DistributionConfig": {
          "Origins": [
            {
              "DomainName": {
                "Fn::GetAtt": [
                              "AssetBucket",
                              "DomainName"
                          ]
              },
              "Id": "AssetBucketOrigin",
              "S3OriginConfig": {}
            }
          ],
          "Enabled": "true",
          "DefaultCacheBehavior": {
            "Compress": true,
            "AllowedMethods": [
              "GET",
              "HEAD",
              "OPTIONS"
            ],
            "TargetOriginId": "origin-access-identity/cloudfront/AssetCDN",
            "ForwardedValues": {
              "QueryString": "false",
              "Cookies": {
                "Forward": "none"
              }
            },
            "ViewerProtocolPolicy": "allow-all"
          },
          "PriceClass": "PriceClass_All",
          "ViewerCertificate": {
            "CloudFrontDefaultCertificate": "true"
          }
        }
      },
      "DependsOn": [
        "AssetBucket"
      ]
    }
  }
}


我在这方面找不到很多建议,因此希望有人可以指出正确的方向。

最佳答案

缓存行为的TargetOriginId属性必须与S3 Origin的Id属性中指定的值匹配。

在上面的示例中,TargetOriginIdorigin-access-identity/cloudfront/AssetCDN,而IdAssetBucketOrigin,这会导致错误。

关于amazon-cloudformation - 使用CloudFormation以S3来源配置CloudFront,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35851374/

10-11 10:33