Skip to content

Unable to reference subnet group name tag on an imported VPC  #7580

@dassowmd

Description

@dassowmd

I am not able to reference a custom subnet group name on an imported VPC. I have tried to reference both the default tag (aws-cdk:subnet-name) and also by passing the a custom tag key to the vpc.from_lookup() method. Both to no avail unless I manually prebuild my cdk.context.json and commit to my repo.

This issue seems related to #3650 which is marked as resolved, but does not appear to be functioning as expected.

Reproduction Steps

` vpc = aws_ec2.Vpc.from_lookup(self
, "VPC"
, vpc_name='VPC1'
, subnet_group_name_tag='custom-subnet-group-tag-name'
)

    host = aws_ec2.Instance(<my_stack>
                            ,windows_powerbi_gateway_server_name,
                            instance_type=ec2.InstanceType(
                            instance_type_identifier='t2.large'),
                            instance_name='some_name',
                            machine_image=<windows_ami>,
                            vpc=vpc,
                            key_name='some_key',
                            vpc_subnets=ec2.SubnetSelection(subnet_group_name="application_layer")
                       )

`

Error Log

If I run the above code with an empty context I get the following error:
vpc_subnets=ec2.SubnetSelection(subnet_group_name="application") File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_runtime.py", line 66, in __call__ inst = super().__call__(*args, **kwargs) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\aws_cdk\aws_ec2\__init__.py", line 22158, in __init__ jsii.create(Instance, self, [scope, id, props]) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\__init__.py", line 229, in create interfaces=[iface.__jsii_type__ for iface in getattr(klass, "__jsii_ifaces__", [])], File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\providers\process.py", line 333, in create return self._process.send(request, CreateResponse) File "C:\Users\<username>\AppData\Local\Programs\Python\Python37\lib\site-packages\jsii\_kernel\providers\process.py", line 318, in send raise JSIIError(resp.error) from JavaScriptError(resp.stack) jsii.errors.JSIIError: Cannot read property 'subnetId' of undefined Subprocess exited with error 1

If I prebuild my cdk.context.json and rerun it successfully builds. While I recognize this work around fixes the immediate issue, it also creates technical debt because now any time I deploy the stack to a new account or region I have to update my cdk.context.json manually.

Environment

  • **CLI Version :1.33.0
  • **Framework Version :
  • **OS : Windows 10
  • **Language :Python 3.7.6

Other

I believe that the issue is that the CDK is relying on the dummy vpc instead of making the call to get the context before trying to make the aws_ec2.Instance() call. If it were to instead fetch the context first I believe it would fix the issue.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-ec2Related to Amazon Elastic Compute CloudbugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions