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.

(vpc): cant reference a default sg when choosing a existing vpc

See original GitHub issue

General Issue

cant reference a default sg when choosing a existing vpc

The Question

This is my cdk code:


        # choose or create a vpc
        if use_default_vpc == 1:
            self.vpc = ec2.Vpc.from_lookup(self, 'VPC', is_default = True) 
        elif vpc_id != "":
            self.vpc = ec2.Vpc.from_lookup(self, 'VPC', is_default = False,vpc_id = vpc_id) 
        else:
            self.vpc = ec2.Vpc(self, "VPC",
            max_azs=1, # single AZ
            subnet_configuration=[
                {"name":"public","subnetType":ec2.SubnetType.PUBLIC},
                {"name":"private","subnetType":ec2.SubnetType.PRIVATE}
                ]
            )


        # create fsx for lustre, if we use 2.4T storage, then must apply LZ4 compression, but not found in cdk?

        self.file_system = fsx.LustreFileSystem(
            self,'FSX',
            lustre_configuration={"deployment_type": fsx.LustreDeploymentType.PERSISTENT_1,
                                    "per_unit_storage_throughput":100}, # 
            vpc = self.vpc,
            vpc_subnet=self.vpc.public_subnets[0],
            storage_capacity_gib = 4800,

            ##### 
            removal_policy=cdk.RemovalPolicy.DESTROY,
            security_group = ec2.SecurityGroup.from_security_group_id(
                                self,"FSXSG",
                                security_group_id=self.vpc.vpc_default_security_group
                            ),
        )

the sg of fsx works fine when creating a new vpc, but when it comes to using the default vpc or manually choosing a vpc via vpcid, got error for:

cdk synth

Traceback (most recent call last):
  File "app.py", line 36, in <module>
    vpc_stack = EC2VPCCdkStack(app, "EC2VPCCdkStack",
  File "/Users/twuam/Library/Python/3.8/lib/python/site-packages/jsii/_runtime.py", line 86, in __call__
    inst = super().__call__(*args, **kwargs)
  File "/Users/twuam/Desktop/AWSome Builder/2&3/af2-batch-cdk/af2_batch_cdk/vpc_ec2.py", line 106, in __init__
    self, "default_security_group", self.vpc.vpc_default_security_group
  File "/Users/twuam/Library/Python/3.8/lib/python/site-packages/jsii/_reference_map.py", line 149, in __getattr__
    raise AttributeError(f"'%s' object has no attribute '%s'" % (type_info, name))
AttributeError: '<class 'aws_cdk.core.Resource'>+<class 'aws_cdk.aws_ec2._IVpcProxy'>' object has no attribute 'vpc_default_security_group'
Subprocess exited with error 1

how am I supposed to solve this?

CDK CLI Version

1.128.0 (build 1d3883a)

Framework Version

No response

Node.js Version

No response

OS

No response

Language

Python

Language Version

No response

Other information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
peterwoodworthcommented, Oct 20, 2021

Thanks for the response @jumic

I’ll try to get your proposed solution gets looked at soon, this is highly desired by customers so it should be high priority 😃

0reactions
github-actions[bot]commented, Oct 20, 2021

⚠️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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Default and custom security groups - AWS Documentation
A security group name cannot start with the following: sg-. A security group name must be unique for the VPC. The following are...
Read more >
VPC Configuration - eksctl
You can use the VPC of an existing Kubernetes cluster managed by kops. This feature is provided to facilitate migration and/or cluster peering....
Read more >
Retrieve a VPC to create a security group - Stack Overflow
I have code like so: const primaryVpcId = config.require("primaryVpcId"); const primaryVpc = awsx.ec2.Vpc.fromExistingIds("primary", { vpcId: ...
Read more >
AWS CloudFormation: VPC default security group - Server Fault
Referencing the default security group is possible using: { "Fn::GetAtt" : ["VPC", "DefaultSecurityGroup"] }. Where "VPC" is your VPC ...
Read more >
Customer-managed VPC | Databricks on AWS
By default, clusters are created in a single AWS VPC (Virtual Private ... Reference your VPC network configuration with Databricks when you ...
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