- Newest
- Most votes
- Most comments
Hello.
I think it's probably because I'm using version 2 of CDK.
https://aws.amazon.com/jp/blogs/developer/experimental-construct-libraries-are-now-available-in-aws-cdk-v2/
I think the error occurred because the core module disappeared in CDK version 2.
https://docs.aws.amazon.com/cdk/v2/guide/migrating-v2.html
AWS CDK v2 consolidates the stable parts of the AWS Construct Library, including the core library, into a single package, aws-cdk-lib. Developers no longer need to install additional packages for the individual AWS services they use. This single-package approach also means that you don't have to synchronize the versions of the various CDK library packages.
So I think you need to do something like this:
from aws_cdk import (
aws_elasticloadbalancingv2 as elbv2,
aws_ec2 as ec2
)
from constructs import Construct
could you help me with the complete code as I have provided above? I am a bit confused here.
I think it will look something like this.
from aws_cdk import ( aws_elasticloadbalancingv2 as elbv2, aws_ec2 as ec2 ) from constructs import Construct class MyStack(core.Stack): def __init__(self, scope: core.Construct, id: str, **kwargs) -> None: super().__init__(scope, id, **kwargs) vpc = ec2.Vpc(self, 'MyVpc') nlb = elbv2.NetworkLoadBalancer(self, 'MyNlb', vpc=vpc, internet_facing=True ) # Add a listener to the load balancer nlb.add_listener('MyListener', port=80, open=True )
Traceback (most recent call last): File "/home/gowtham/cdk_workshop/app.py", line 5, in <module> from cdk_workshop.cdk_workshop_stack import CdkWorkshopStack File "/home/gowtham/cdk_workshop/cdk_workshop/cdk_workshop_stack.py", line 7, in <module> class MyStack(core.Stack): NameError: name 'core' is not defined Thanks for looking into it.
Will it work if I change it like below?
class MyStack(Stack):
I will try now
Relevant content
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 months ago
Kindly suggest