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.

aws_cloudfront.CustomOriginConfig not working in Python

See original GitHub issue

I am facing a issue with using aws_cloudfront.CustomOriginConfig in Python. I know this class is still at experimental release, but I would greatly appreciate any help/comments that may resolve my issue.

Reproduction Steps

I am trying to set up a CloudFront distribution with two origins, S3 and API Gateway. Below is the code snippet to prepare the distribution.

import aws_cloudfront as cfront

...

# define cloudfront distribution
distribution = cfront.CloudFrontWebDistribution(
   self, "CloudFrontDistribution",
   origin_configs=[
         cfront.SourceConfiguration(
            s3_origin_source=cfront.S3OriginConfig(
               s3_bucket_source=site_bucket,
               origin_access_identity_id=props.oia.ref
            ),
            behaviors=[cfront.Behavior(is_default_behavior=True)],
         ),
         cfront.SourceConfiguration(
            custom_origin_source=cfront.CustomOriginConfig(
               domain_name=props.apigw_domain_name
            ),
            behaviors=[cfront.Behavior(
               allowed_methods=cfront.CloudFrontAllowedMethods.ALL,
               path_pattern="/api"
            )]
         )
   ],
)

Error Log

Here is the error message I got when I ran cdk synth.

jsii.errors.JSIIError: Got ‘undefined’ for non-optional instance of {“abstract”:true,“docs”:{“remarks”:“Should not include the path - that should be in the parent SourceConfiguration”,“stability”:“experimental”,“summary”:“The domain name of the custom origin.”},“immutable”:true,“locationInModule”:{“filename”:“lib/web_distribution.ts”,“line”:179},“name”:“domainName”,“type”:{“primitive”:“string”}}

If I delete the CustomOriginConfig part (i.e. only with S3 origin), the build succeeds.

I am thinking that this may be a bug in the CDK. Or, am I using the functions in a wrong way?

Environment

  • **CLI Version : CDK v1.15
  • Framework Version:
  • **OS : Ubuntu 16.04 LTS
  • **Language : Python 3.7

Other


This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
eladbcommented, Nov 26, 2019

@tomomano api.domainName refers to a DomainName object which is relevant when using custom domains.

This property may be null in case your APIGW does not have a custom domain. If it’s not null (which seems to be the case), and you want the actual domain name, you will need to use the api.domain_name.domain_name property.

Please reopen if this doesn’t help resolve the issue.

0reactions
toleabivolcommented, Nov 26, 2019

ok - figured it out :

oai = cloudfront.CfnCloudFrontOriginAccessIdentity(
            self, f'origin-access-identity-{stage}-{app_name}-{version}',
            cloud_front_origin_access_identity_config=cloudfront.CfnCloudFrontOriginAccessIdentity
            .CloudFrontOriginAccessIdentityConfigProperty(
                comment=f'origin-access-identity-{stage}-{app_name}-{version}'
            )
        )
Read more comments on GitHub >

github_iconTop Results From Across the Web

interface CustomOriginConfig · AWS CDK - AWS Documentation
domainName. Type: string. The domain name of the custom origin. Should not include the path - that should be in the parent SourceConfiguration ......
Read more >
AWS::CloudFront::Distribution CustomOriginConfig
A custom origin is any origin that is not an Amazon S3 bucket, with one exception. An Amazon S3 bucket that is configured...
Read more >
aws-cdk/aws-cloudfront-origins module - AWS Documentation
This can be used in conjunction with a bucket that is not public to require that your users access your content using CloudFront...
Read more >
Using various origins with CloudFront distributions
When you create the distribution, specify the name of your Amazon S3 bucket as the origin server. Important. For your bucket to work...
Read more >
interface CustomOriginConfig · AWS CDK - AWS Documentation
Go, github.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#CustomOriginConfig. Java, software.amazon.awscdk.services.cloudfront.CustomOriginConfig. Python ...
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