aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.59k stars 3.89k forks source link

(aws_cdk.aws_codecommit): AttributeError: module 'aws_cdk.aws_codecommit' has no attribute 'Code' #19873

Closed fmcmac closed 2 years ago

fmcmac commented 2 years ago

Describe the bug

codecommit has a class Code per the documentation: https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_codecommit.Code.html

When attempting to access the class...

    repo = codecommit.Repository(
        self,
        "repo",
        repository_name="repo_name",
        description="My repo",
        code=codecommit.Code.from_directory("./mydirectory","main" )
    )

An error is returned...

File "/.../infrastructure.py", line 453, in __init__
    code=codecommit.Code.from_directory("./mydirectory","main" )
AttributeError: module 'aws_cdk.aws_codecommit' has no attribute 'Code'

Expected Behavior

codecommit successfully creates a repo initialized based on the code.

Current Behavior

An error is returned...

File "/.../infrastructure.py", line 453, in __init__
    code=codecommit.Code.from_directory("./mydirectory","main" )
AttributeError: module 'aws_cdk.aws_codecommit' has no attribute 'Code'

Reproduction Steps

    repo = codecommit.Repository(
        self,
        "repo",
        repository_name="repo_name",
        description="MWAA Dag",
        code=codecommit.Code.from_directory("./mydirectory","main" )
    )

Possible Solution

No response

Additional Information/Context

No response

CDK CLI Version

2.20.0 (build 738ef49)

Framework Version

No response

Node.js Version

v16.6.1

OS

ProductName: macOS ProductVersion: 11.6.5 BuildVersion: 20G527

Language

Python

Language Version

Python 3.8.3

Other information

No response

skinny85 commented 2 years ago

Hi @fmcmac,

thanks for opening the issue, but I cannot reproduce it.

This works for me:

from aws_cdk import (
    Stack,
    aws_codecommit as codecommit,
)
from constructs import Construct

class CodecommitCodeInPython19873Stack(Stack):

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

        codecommit.Repository(
            self, 'Repository',
            repository_name='my-repo',
            description='My repo',
            code=codecommit.Code.from_directory('./mydirectory', 'main'),
        )

Can you show the output of pip list in your project?

Thanks, Adam

fmcmac commented 2 years ago

❯ pip list Package Version


altair 4.1.0 appnope 0.1.2 argon2-cffi 21.1.0 attrs 21.2.0 aws-cdk-lib 2.2.0 awscli 1.22.5 backcall 0.2.0 backports.zoneinfo 0.2.1 black 21.10b0 bleach 4.1.0 boto3 1.20.5 botocore 1.23.5 cachetools 4.2.4 cattrs 1.8.0 certifi 2021.10.8 cffi 1.15.0 charset-normalizer 2.0.7 click 8.0.3 colorama 0.4.3 constructs 10.0.9 debugpy 1.5.1 decorator 5.1.0 defusedxml 0.7.1 docutils 0.15.2 entrypoints 0.3 google-api-core 2.2.2 google-auth 2.3.3 google-cloud-bigquery 2.30.1 google-cloud-core 2.2.1 google-crc32c 1.3.0 google-resumable-media 2.1.0 googleapis-common-protos 1.53.0 great-expectations 0.13.42 grpcio 1.41.1 grpcio-status 1.41.1 idna 3.3 importlib-metadata 4.8.2 importlib-resources 5.4.0 ipykernel 6.5.0 ipython 7.29.0 ipython-genutils 0.2.0 ipywidgets 7.6.5 jedi 0.18.0 Jinja2 3.0.3 jmespath 0.10.0 jsii 1.56.0 jsonpatch 1.32 jsonpointer 2.2 jsonschema 4.2.1 jupyter-client 7.0.6 jupyter-core 4.9.1 jupyterlab-pygments 0.1.2 jupyterlab-widgets 1.0.2 MarkupSafe 2.0.1 matplotlib-inline 0.1.3 mistune 0.8.4 mypy-extensions 0.4.3 nbclient 0.5.8 nbconvert 6.3.0 nbformat 5.1.3 nest-asyncio 1.5.1 notebook 6.4.5 numpy 1.21.4 openlineage-airflow 0.3.1 openlineage-integration-common 0.3.1 openlineage-python 0.3.1 packaging 21.2 pandas 1.3.4 pandocfilters 1.5.0 parso 0.8.2 pathspec 0.9.0 pep517 0.12.0 pexpect 4.8.0 pickleshare 0.7.5 pip 22.0.4 pip-tools 6.6.0 platformdirs 2.4.0 prometheus-client 0.12.0 prompt-toolkit 3.0.22 proto-plus 1.19.8 protobuf 3.19.1 ptyprocess 0.7.0 publication 0.0.3 pyasn1 0.4.8 pyasn1-modules 0.2.8 pycparser 2.21 Pygments 2.10.0 pyparsing 2.4.7 pyrsistent 0.18.0 python-dateutil 2.8.2 pytz 2021.3 pytz-deprecation-shim 0.1.0.post0 PyYAML 5.4.1 pyzmq 22.3.0 regex 2021.11.10 requests 2.26.0 rsa 4.7.2 ruamel.yaml 0.17.17 ruamel.yaml.clib 0.2.6 s3transfer 0.5.0 scipy 1.7.2 Send2Trash 1.8.0 setuptools 41.2.0 six 1.16.0 sqlparse 0.4.2 termcolor 1.1.0 terminado 0.12.1 testpath 0.5.0 tomli 1.2.2 toolz 0.11.2 tornado 6.1 tqdm 4.62.3 traitlets 5.1.1 typing-extensions 3.10.0.2 tzdata 2021.5 tzlocal 4.1 urllib3 1.26.7 wcwidth 0.2.5 webencodings 0.5.1 wheel 0.37.1 widgetsnbextension 3.5.2 zipp 3.6.0

fmcmac commented 2 years ago

Looks like this was due to incorrect install_requires. When the below was added this works. install_requires=[ "aws-cdk-lib>=2.0.0", "constructs>=10.0.0", "aws-cdk.aws-codestar-alpha>=2.0.0alpha1",

...

],

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

skinny85 commented 2 years ago

Yes, you were using aws-cdk-lib in version 2.2.0, while this functionality was released in version 2.4.0.

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.