question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cloudfront customOriginSource with s3 reference seems to be broken

See original GitHub issue

Given the following resources:

const bucket = new s3.Bucket(this, `${props.name}Bucket`, {
  publicReadAccess: true,
  websiteIndexDocument: "index.html",
  websiteErrorDocument: "404.html",
  removalPolicy: cdk.RemovalPolicy.Orphan
});


new cloudfront.CloudFrontWebDistribution(
  this,
  `${props.name}Distribution`,
  {
    aliasConfiguration: {
      names: props.domainNames,
      acmCertRef: props.certificateArn 
    },
    viewerProtocolPolicy: cloudfront.ViewerProtocolPolicy.RedirectToHTTPS,
    priceClass: cloudfront.PriceClass.PriceClass200,
    originConfigs: [
      {
        customOriginSource: {
          originProtocolPolicy: cloudfront.OriginProtocolPolicy.HttpOnly,
          domainName: bucket.bucketWebsiteUrl
        },
        behaviors: [{ isDefaultBehavior: true }]
      }
    ]
  }
);

The stack synthesizes properly, but the creation fails with the following error message:

 5/10 | 11:37:27 PM | CREATE_FAILED        | AWS::CloudFront::Distribution | LivejamDistribution/LivejamMainDistribution/CFDistribution (LivejamDistributionLivejamMainDistributionCFDistribution579AF62B) The parameter origin name cannot contain a colon. (Service: AmazonCloudFront; Status Code: 400; Error Code: InvalidArgument; Request ID: ed592c47-394d-11e9-9a3d-7928c3cc16b1)

When I provide the domainName as string input, it works as expected.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

27reactions
vahdetcommented, Jun 2, 2019

A quick workaround for getting rid of http:// or https:// is splitting the WebsiteURL of the bucket. See the DomainName value in the following snippet:

Resources:
  MyBucket:
    Type: AWS::S3::Bucket
    ...

  MyCloudFrontDistribution:
    Type: AWS::CloudFront::Distribution
    Properties:
      DistributionConfig:
        Enabled: true
        Origins:
          - Id: MyCloudFrontDistributionId
            DomainName: !Select [1, !Split ["//", !GetAtt MyBucket.WebsiteURL]]
            CustomOriginConfig:
              ...
8reactions
PinkyJiecommented, Aug 6, 2019

For anyone others who stumble into the same issues, I found 2 working solutions:

customOriginSource: {
 domainName: URL.substring("https://".length, URL.indexOf("/", "https://".length))
},
customOriginSource: {
  domainName: cdk.Fn.select(2, cdk.Fn.split("/", URL))
},
Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot CloudFront file access with an S3 origin
I'm using an Amazon Simple Storage Service (Amazon S3) bucket as the origin of my Amazon CloudFront distribution but I'm not able to...
Read more >
AWS CDK: There can only be one default behavior across all ...
It means that you need to have only single default behavior. But you can add multiple behaviors. Cloudfront let's you create multiple behaviors ......
Read more >
Deploying create-react-app to S3 and CloudFront
The React CLI tool, create-react-app, helps front end developers finally focus on building applications, rather than configuring them.
Read more >
Why You Shouldn't Use AWS S3 or CloudFront to Deliver ...
AWS is THE cool kid in the town. Every comparison of different cloud providers is incomplete unless you compare them with AWS at...
Read more >
Getting started with a simple CloudFront distribution
Stores the original versions of your objects in an Amazon Simple Storage Service (Amazon S3) bucket. Makes your objects accessible to everyone. Uses...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found