Fix DescribeInstances error due to a deleted subnet (#6112)
This commit is contained in:
parent
c3460b8a1a
commit
f01709f9ba
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user