Fix DescribeInstances error due to a deleted subnet (#6112)

This commit is contained in:
Viren Nadkarni 2023-03-23 15:56:49 +05:30 committed by GitHub
parent c3460b8a1a
commit f01709f9ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,3 +1,4 @@
import contextlib
import copy import copy
import warnings import warnings
from collections import OrderedDict from collections import OrderedDict
@ -28,6 +29,7 @@ from ..exceptions import (
InvalidParameterValueErrorUnknownAttribute, InvalidParameterValueErrorUnknownAttribute,
InvalidSecurityGroupNotFoundError, InvalidSecurityGroupNotFoundError,
OperationNotPermitted4, OperationNotPermitted4,
InvalidSubnetIdError,
) )
from ..utils import ( from ..utils import (
convert_tag_spec, convert_tag_spec,
@ -185,8 +187,9 @@ class Instance(TaggedEC2Resource, BotoInstance, CloudFormationModel):
@property @property
def vpc_id(self) -> Optional[str]: def vpc_id(self) -> Optional[str]:
if self.subnet_id: if self.subnet_id:
subnet: Subnet = self.ec2_backend.get_subnet(self.subnet_id) with contextlib.suppress(InvalidSubnetIdError):
return subnet.vpc_id subnet: Subnet = self.ec2_backend.get_subnet(self.subnet_id)
return subnet.vpc_id
if self.nics and 0 in self.nics: if self.nics and 0 in self.nics:
return self.nics[0].subnet.vpc_id return self.nics[0].subnet.vpc_id
return None return None