  def GetInstancesByNameOrId(
      self,
      instance_name: Optional[str] = None,
      instance_id: Optional[str] = None,
      region: Optional[str] = None) -> List[AWSInstance]:
    """Get instances from an AWS account by their name tag or an ID.

    Exactly one of [instance_name, instance_id] must be specified. If looking up
    an instance by its ID, the method returns a list with exactly one
    element. If looking up instances by their name tag (which are not unique
    across instances), then the method will return a list of all instances
    with that name tag, or an empty list if no instances with matching name
    tag could be found.

    Args:
      instance_name (str): Optional. The instance name tag of the instance to
          get.
      instance_id (str): Optional. The instance id of the instance to get.
      region (str): Optional. The region to look the instance in.
          If none provided, the default_region associated to the AWSAccount
          object will be used.

    Returns:
      List[AWSInstance]: A list of Amazon EC2 Instance objects.

    Raises:
      ValueError: If both instance_name and instance_id are None or if both
          are set.
    """

    if (not instance_name and not instance_id) or (instance_name and instance_id):  # pylint: disable=line-too-long
      raise ValueError('You must specify exactly one of [instance_name, '
                       'instance_id]. Got instance_name: {0:s}, instance_id: '
                       '{1:s}'.format(str(instance_name), str(instance_id)))
    if instance_name:
      return self.GetInstancesByName(instance_name, region=region)
    # mypy complains that instance_id may be None here, but at this point in the
    # code it never is, so it's safe to ignore the warning.
    return [self.GetInstanceById(instance_id, region=region)]  # type: ignore
Get instances from an AWS account by their name tag or an ID.

Exactly one of [instance_name, instance_id] must be specified. If looking up
an instance by its ID, the method returns a list with exactly one
element. If looking up instances by their name tag (which are not unique
across instances), then the method will return a list of all instances
with that name tag, or an empty list if no instances with matching name
tag could be found.

Args:
instance_name (str): Optional. The instance name tag of the instance to
get.
instance_id (str): Optional. The instance id of the instance to get.
region (str): Optional. The region to look the instance in.
If none provided, the default_region associated to the AWSAccount
object will be used.

Returns:
List[AWSInstance]: A list of Amazon EC2 Instance objects.

Raises:
ValueError: If both instance_name and instance_id are None or if both
are set.
libcloudforensics/providers/aws/internal/ec2.py