Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFormation creation of CloudFront distribution with logging bucket

Trying to provision a static website bucket that's distributed by CloudFront.

The following CloudFormation template works if I omit the Logging configuration for the distribution:

{
...

"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"
}
}

If I include Logging I get the error:

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

Is there any extra magic that needs to be applied to the logging bucket in order for it to be compatible with CloudFront? Couldn't find anything in the docs.

like image 356
Assaf Lavie Avatar asked Mar 07 '16 17:03

Assaf Lavie


People also ask

How do I enable logging in CloudFront?

Click on the “ON” option to initiate the Logging feature of CloudFront to log all viewer requests for files in your distribution. Click on “Bucket for Logs” feature and specify the Amazon S3 bucket in which you want CloudFront to save web access logs. Click on Log Prefix which is optional for the names of log files.

When creating an AWS CloudFront distribution Which of the following is not an origin?

1 Answer. The correct answer is option A (CloudFront cannot serve content from a non-AWS origin server). We can configure multiple origin servers for Amazon CloudFront. They can be either Amazon resources or non-AWS origin servers.

Where are CloudFront access logs stored?

Standard logs (access logs) CloudFront standard logs are delivered to the Amazon S3 bucket of your choice. CloudFront doesn't charge for standard logs, though you incur Amazon S3 charges for storing and accessing the log files.


1 Answers

Try specifying your bucket name as "bucketname.s3.amazonaws.com" instead of just "bucketname".

like image 155
Tyler Ham Avatar answered Nov 15 '22 11:11

Tyler Ham