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): jsii.errors.JSIIError: Cannot read property 'uniqueId' of undefined

See original GitHub issue

getting this error when ‘cdk synth’ is run. I have pasted the entire code. It is the example code specified on reference docs.

Reproduction Steps

from aws_cdk import ( 
    core,
    aws_cloudfront as cfront,
    aws_cloudfront_origins as cforigins,
    aws_s3 as s3,
    aws_certificatemanager as acm
)
from variables_list import (
    Project,
    Env
)

class CdnStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        # The code that defines your stack goes here
        core.Tag.add(self,key='environment',value=Env)
        core.Tag.add(self,key='project',value=Project)

        my_bucket = s3.Bucket(self, "myBucket")

        cfront.Distribution(self, "myDist",
        default_behavior= cfront.BehaviorOptions(
            origin=cforigins.S3Origin(my_bucket)
            )
        )

What did you expect to happen?

I am trying to create CloudFront distribution with s3 origin.

Error:

jsii.errors.JavaScriptError: TypeError: Cannot read property ‘uniqueId’ of undefined at Distribution.addOrigin (/tmp/jsii-kernel-i86csu/node_modules/@aws-cdk/aws-cloudfront/lib/distribution.js:108:43) at new Distribution (/tmp/jsii-kernel-i86csu/node_modules/@aws-cdk/aws-cloudfront/lib/distribution.js:35:31) at /home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7932:49 at Kernel._wrapSandboxCode (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:8420:19) at Kernel._create (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7932:26) at Kernel.create (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7676:21) at KernelHost.processRequest (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7456:28) at KernelHost.run (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7394:14) at Immediate._onImmediate (/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_embedded/jsii/jsii-runtime.js:7397:37) at processImmediate (internal/timers.js:456:21)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File “app.py”, line 246, in <module> cdn_stack = CdnStack( File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_runtime.py”, line 69, in call inst = super().call(*args, **kwargs) File “/home/administrator/repos/devops/automation/cdk_codes/stage/stage/cdn_stack.py”, line 24, in init cfront.Distribution(self, “myDist”, File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_runtime.py”, line 69, in call inst = super().call(*args, **kwargs) File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/aws_cdk/aws_cloudfront/init.py”, line 9216, in init jsii.create(Distribution, self, [scope, id, props]) File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_kernel/init.py”, line 246, in create response = self.provider.create( File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py”, line 336, in create return self._process.send(request, CreateResponse) File “/home/administrator/repos/devops/automation/cdk_codes/stage/.env/lib/python3.8/site-packages/jsii/_kernel/providers/process.py”, line 321, in send raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: Cannot read property ‘uniqueId’ of undefined

Environment

  • CDK CLI Version : 1.79.0
  • Node.js Version: v13.9.0
  • OS : Linux
  • Language (Version): Python3.8

This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
njlynchcommented, Feb 9, 2021

Ah, that’s the issue then; the Distribution construct was released in version 1.52.0. When you use the CDK, all versions must be in sync – you can’t use 1.52.0 (or newer) of CloudFront and 1.34.0 of Core.

Your options are either to go through the work of upgrading your application to a newer version, or using the CloudFrontWebDistribution construct instead of Distribution.

I’m going to resolve this, but feel free to reopen if you have any follow-up questions.

0reactions
NadeemPatelcommented, Feb 9, 2021

thank you very much @njlynch

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of undefined (reading 'startsWith ...
However when I try to deploy the lambda@edge function with the suggested Node JS code it throws error Cannot read properties of undefined...
Read more >
Troubleshooting common AWS CDK issues
This topic describes how to troubleshoot the following issues with the AWS CDK.
Read more >
Cookie based routing on CloudFront | AWS re:Post
or it says "Cannot read properties of undefined (reading 'custom')" when I send another cookie value. My code is this and using runtime...
Read more >
ERROR TypeError: Cannot read property title of undefined
HEY, SET YOUR LIKE THERE ! ... Your browser can't play this video. ... Solved: ERROR TypeError: Cannot read property title of undefined....
Read more >
TypeError: Cannot read property 'data' of undefined
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
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