  def SetInstanceSecurityGroup(
      self,
      instance_id: str,
      sg_id: str) -> None:
    """Attach a security group to an instance, removing all others.

    Args:
      instance_id (str): The instance ID (i-xxxxxx)
      sg_id (str): The Security Group ID (sg-xxxxxx)

    Raises:
      ResourceCreationError: If the instance or security group cannot be found.
    """
    client = self.aws_account.ClientApi(common.EC2_SERVICE)

    try:
      client.modify_instance_attribute(
        Groups=[sg_id],
        InstanceId=instance_id
      )
    except client.exceptions.ClientError as exception:
      raise errors.ResourceCreationError(
        'Could not modify instance attributes: {0!s}'.format(
           exception), __name__) from exception
Attach a security group to an instance, removing all others.

Args:
instance_id (str): The instance ID (i-xxxxxx)
sg_id (str): The Security Group ID (sg-xxxxxx)

Raises:
ResourceCreationError: If the instance or security group cannot be found.
libcloudforensics/providers/aws/internal/ec2.py