def METHOD_NAME(self, key_name):
    """
    Creates a key pair that can be used to securely connect to an EC2 instance.
    The returned key pair contains private key information that cannot be retrieved
    again. The private key data is stored as a .pem file.
    :param key_name: The name of the key pair to create.
    :return: A Boto3 KeyPair object that represents the newly created key pair.
    """
    try:
        self.key_pair = self.ec2_resource.create_key_pair(KeyName=key_name)
        self.key_file_path = os.path.join(self.key_file_dir.name, f'{self.key_pair.name}.pem')
        with open(self.key_file_path, 'w') as key_file:
            key_file.write(self.key_pair.key_material)
    except ClientError as err:
        logger.error(
            "Couldn't create key %s. Here's why: %s: %s", key_name,
            err.response['Error']['Code'], err.response['Error']['Message'])
        raise
    else:
        return self.key_pair