aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.67k stars 1.01k forks source link

Failed to create CDK project in CDK >= 2.73.0 #2088

Open ShotaOki opened 10 months ago

ShotaOki commented 10 months ago

procedure

  1. Install libraries.
    -> Reference :: https://aws.github.io/chalice/tutorials/cdk.html
npm install -g aws-cdk

python3 -m pip install chalice "chalice[cdkv2]"
  1. chalice new-project

Select [CDK] REST API with DynamoDB backend

  1. deploy
python3 -m pip install -r requirements.txt

cdk deploy

Result

Failed to deploy. Traceback

Traceback (most recent call last):
  File "/home/USERNAME/ChaliceA4AB/example/jp/sandwich-shop/infrastructure/app.py", line 4, in <module>
    from aws_cdk import core as cdk
  File "/home/USERNAME/.local/lib/python3.9/site-packages/aws_cdk/core/__init__.py", line 7501, in <module>
    class ConstructNode(metaclass=jsii.JSIIMeta, jsii_type="@aws-cdk/core.ConstructNode"):
  File "/home/USERNAME/.local/lib/python3.9/site-packages/aws_cdk/core/__init__.py", line 7560, in ConstructNode
    runtime_info: typing.Optional[typing.Union[_aws_cdk_cx_api_9a62db47.RuntimeInfo, typing.Dict[builtins.str, typing.Any]]] = None,
AttributeError: module 'aws_cdk.cx_api' has no attribute 'RuntimeInfo'

Reason

CDK v2.72.0 has no package aws_cdk.core https://github.com/aws/aws-cdk/tree/v2.72.0/packages/aws-cdk-lib/core

But CDK v2.73.0 later, package has aws_cdk.core https://github.com/aws/aws-cdk/tree/v2.73.0/packages/aws-cdk-lib/core

Chalice determines the version in this way. But 2.73.0 later, this source does not work correctly.

try:
    from aws_cdk import core as cdk # As V1
except ImportError:
    import aws_cdk as cdk # As V2