CloudFormation使用日志记录存储桶创建CloudFront分配

时间:2016-03-07 17:39:55

标签: amazon-s3 amazon-cloudfront amazon-cloudformation

尝试配置由CloudFront分发的静态网站存储桶。

如果我省略了分发的Logging配置,则以下CloudFormation模板可用:

{
...

"PrimeBucket": {
    "Properties": {
        "AccessControl": "PublicRead",
        "WebsiteConfiguration": {
            "ErrorDocument": "error.html",
            "IndexDocument": "index.html"
        }
    },
    "Type": "AWS::S3::Bucket"
},
"PrimeBucketDistribution": {
    "Properties": {
        "DistributionConfig": {
            "DefaultCacheBehavior": {
                "AllowedMethods": [
                    "GET",
                    "HEAD",
                    "OPTIONS"
                ],
                "ForwardedValues": {
                    "QueryString": "false"
                },
                "TargetOriginId": "BucketOrigin",
                "ViewerProtocolPolicy": "allow-all"
            },
            "Enabled": "true",
            "Logging": {
                "Bucket": {
                    "Ref": "PrimeBucketLogs"
                },
                "IncludeCookies": "false"
            },
            "Origins": [
                {
                    "DomainName": {
                        "Fn::GetAtt": [
                            "PrimeBucket",
                            "DomainName"
                        ]
                    },
                    "Id": "BucketOrigin",
                    "S3OriginConfig": {}
                }
            ]
        }
    },
    "Type": "AWS::CloudFront::Distribution"
},
"PrimeBucketLogs": {
    "Type": "AWS::S3::Bucket"
}
}

如果我包含Logging,我会收到错误:

The parameter Logging Bucket does not refer to a valid S3 bucket.

是否需要将额外的魔法应用于日志记录存储桶以使其与CloudFront兼容?无法在文档中找到任何内容。

1 个答案:

答案 0 :(得分:8)

尝试将您的广告位名称指定为"bucketname.s3.amazonaws.com",而不仅仅是"bucketname"