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.

[monocdk-experiment] Python - import incorrect

See original GitHub issue

When using monocdk-experiment package in Python, stack cannot be created because some package are not imported.

Reproduction Steps

Install dependencies

pip install monocdk.experiment

app.py

#!/usr/bin/env python3
from monocdk_experiment import App, Stack, aws_codebuild

app = App()

class TestStack(Stack):
    def __init__(self, scope, id, **kwargs):
        super().__init__(scope, id, **kwargs)

TestStack(app, "test-stack")

Synthesize stacks

cdk synth

Error Log

Traceback (most recent call last):
  File "app.py", line 2, in <module>
    from monocdk_experiment import App, Stack, aws_codebuild
  File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_codebuild/__init__.py", line 34, in <module>
    from ..aws_ec2 import (
  File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_ec2/__init__.py", line 46, in <module>
    from ..aws_logs import ILogGroup as _ILogGroup_6b54c8e1
  File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/__init__.py", line 2613, in <module>
    class MetricFilter(
  File "/Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/__init__.py", line 2668, in MetricFilter
    period: typing.Optional[_Duration_5170c158] = None,
NameError: name '_Duration_5170c158' is not defined

Environment

  • CLI Version: 1.51.0 (build 8c2d53c)
  • Framework Version: 1.51.0
  • Node.js Version: 12.6
  • OS: Mac OS Catalina 10.15.5
  • Language (Version): Python (3.8.2)

Other

How to fix the error ?

If I open the file /Users/zangror/.venv/lib/python3.8/site-packages/monocdk_experiment/aws_logs/init.py this is the content:

import abc
import builtins
import datetime
import enum
import typing

import jsii
import jsii.compat
import publication

from .._jsii import *

from .. import (
    CfnResource as _CfnResource_7760e8e4,
    Construct as _Construct_f50a3f53,
    FromCloudFormationOptions as _FromCloudFormationOptions_5f49f6f1,
    ICfnFinder as _ICfnFinder_3b168f30,
    TreeInspector as _TreeInspector_154f5999,
    IInspectable as _IInspectable_051e6ed8,
    IResolvable as _IResolvable_9ceae33e,
    Resource as _Resource_884d0774,
    IResource as _IResource_72f7ee7e,
    RemovalPolicy as _RemovalPolicy_5986e9f3,
)
from ..aws_cloudwatch import (
    Metric as _Metric_53e89548,
    MetricOptions as _MetricOptions_ad2c4d5d,
)
from ..aws_iam import (
    IRole as _IRole_e69bbae4,
    PolicyStatement as _PolicyStatement_f75dc775,
    PolicyDocument as _PolicyDocument_1d1bca11,
    Grant as _Grant_96af6d2d,
    IGrantable as _IGrantable_0fcfc53a,
)

If I add manually this specific dependency, this import error disappears

import abc
import builtins
import datetime
import enum
import typing

import jsii
import jsii.compat
import publication

from .._jsii import *

from .. import (
    CfnResource as _CfnResource_7760e8e4,
    Construct as _Construct_f50a3f53,
    FromCloudFormationOptions as _FromCloudFormationOptions_5f49f6f1,
    ICfnFinder as _ICfnFinder_3b168f30,
    TreeInspector as _TreeInspector_154f5999,
    IInspectable as _IInspectable_051e6ed8,
    IResolvable as _IResolvable_9ceae33e,
    Resource as _Resource_884d0774,
    IResource as _IResource_72f7ee7e,
    RemovalPolicy as _RemovalPolicy_5986e9f3,
    Duration as _Duration_5170c158,  # <-- Here
)
from ..aws_cloudwatch import (
    Metric as _Metric_53e89548,
    MetricOptions as _MetricOptions_ad2c4d5d,
)
from ..aws_iam import (
    IRole as _IRole_e69bbae4,
    PolicyStatement as _PolicyStatement_f75dc775,
    PolicyDocument as _PolicyDocument_1d1bca11,
    Grant as _Grant_96af6d2d,
    IGrantable as _IGrantable_0fcfc53a,
)

It seems that in all the packages, core.Duration, aws_cloudwatch.Unit are not imported correctly, which is really strange because the others imports are well resolved.


This is 🐛 Bug Report

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
RomainMullercommented, Jul 22, 2020

Submitted a PR with a fix in jsii.

1reaction
eladbcommented, Jul 16, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

aws-cdk/assertions module
Functions for writing test asserting against CDK applications, with focus on CloudFormation templates. The Template class includes a set of methods for writing ......
Read more >
@monocdk-experiment/rewrite-imports - npm
Rewrites typescript 'import' statements from @aws-cdk/xxx to monocdk. Latest version: 1.180.0, last published: 5 hours ago.
Read more >
How to migrate CDK v1 to CDK v2 in 10 minuets
Construct by import * as cdk from '@aws-cdk/core'; in CDK v1. ... AND you don't see it wrong, all experimental modules will be...
Read more >
@aws-cdk/assert | Yarn - Package Manager
... type-checking it introduced for Python results in incorrect code being produced. ... monocdk: assert package has incorrect imports (#7404 (825c9e1) ...
Read more >
How to upgrade CDK from CDKv1 to CDKv2 in an existing ...
Experimental modules still need to be installed one by one. ... For this application, which is a python CDK App, a requirements.txt is...
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