diff --git a/moto/ec2/models.py b/moto/ec2/models.py index 73b6301463b5..830080cb1268 100644 --- a/moto/ec2/models.py +++ b/moto/ec2/models.py @@ -3919,13 +3919,6 @@ def __init__(self): self.vpc_refs[self.__class__].add(weakref.ref(self)) super().__init__() - @classmethod - def get_vpc_refs(cls): - for inst_ref in cls.vpc_refs[cls]: - inst = inst_ref() - if inst is not None: - yield inst - def create_vpc( self, cidr_block, @@ -3975,13 +3968,6 @@ def get_vpc(self, vpc_id): raise InvalidVPCIdError(vpc_id) return self.vpcs.get(vpc_id) - # get vpc by vpc id and aws region - def get_cross_vpc(self, vpc_id, peer_region): - for vpcs in self.get_vpc_refs(): - if vpcs.region_name == peer_region: - match_vpc = vpcs.get_vpc(vpc_id) - return match_vpc - def describe_vpcs(self, vpc_ids=None, filters=None): matches = self.vpcs.copy().values() if vpc_ids: diff --git a/moto/ec2/responses/vpc_peering_connections.py b/moto/ec2/responses/vpc_peering_connections.py index 9f90641e86ed..ca119ad7f113 100644 --- a/moto/ec2/responses/vpc_peering_connections.py +++ b/moto/ec2/responses/vpc_peering_connections.py @@ -13,9 +13,9 @@ def create_vpc_peering_connection(self): if peer_region == self.region or peer_region is None: peer_vpc = self.ec2_backend.get_vpc(self._get_param("PeerVpcId")) else: - peer_vpc = self.ec2_backend.get_cross_vpc( - self._get_param("PeerVpcId"), peer_region - ) + from moto.ec2.models import ec2_backends + + peer_vpc = ec2_backends[peer_region].get_vpc(self._get_param("PeerVpcId")) vpc = self.ec2_backend.get_vpc(self._get_param("VpcId")) vpc_pcx = self.ec2_backend.create_vpc_peering_connection(vpc, peer_vpc, tags) template = self.response_template(CREATE_VPC_PEERING_CONNECTION_RESPONSE)