Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CloudFront can't use S3 Website origin, only REST origin Cloudformation

I'm trying to automate spinning up a CloudFront distribution with S3 origin. I'd like to set the origin to the S3 website URL, e.g. mysite.com.s3-website-us-east-1.amazonaws.com. So, I thought my Cloudformation template should look like this:

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
    "myDistribution" : {
        "Type" : "AWS::CloudFront::Distribution",
        "Properties" : {
            "DistributionConfig" : {
                "Origins" : [ {
                    "DomainName" : "mysite.com.s3-website-us-east-1.amazonaws.com",
                    "Id" : "myS3Origin",
...

However that yields the following error:

The parameter Origin DomainName does not refer to a valid S3 bucket.

Which is true, so I can specify the S3 bucket. But I want my origin to be the website endpoint. My non-automated workaround is to deploy with the S3 REST endpoint and update the origin in the UI after.

{
"AWSTemplateFormatVersion" : "2010-09-09",
"Resources" : {
    "myDistribution" : {
        "Type" : "AWS::CloudFront::Distribution",
        "Properties" : {
            "DistributionConfig" : {
                "Origins" : [ {
                    "DomainName" : "mysite.com.s3.amazonaws.com",
                    "Id" : "myS3Origin",
...

According to the docs:

The DNS name of the Amazon Simple Storage Service (S3) bucket or the HTTP server from which you want CloudFront to get objects for this origin.

I can't find anything about a website endpoint origin. http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cloudfront-origin.html#cfn-cloudfront-origin-originpath

like image 223
Dan Stark Avatar asked Mar 16 '17 18:03

Dan Stark


1 Answers

I don't think you've included quite all the relevant parts of your configuration.

The issue here is that an origin that is an S3 website hosting endpoint is not an S3 origin -- it's a custom origin.

Anything other than the REST endpoint of a bucket is always a custom origin.

like image 95
Michael - sqlbot Avatar answered Sep 16 '22 23:09

Michael - sqlbot