<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def ensure_keypair_exists(provider, context, **kwargs):
 """Ensure a specific keypair exists within AWS. If the key doesn't exist, upload it. Args: provider (:class:`stacker.providers.base.BaseProvider`):
 provider instance context (:class:`stacker.context.Context`):
 context instance keypair (str):
 name of the key pair to create ssm_parameter_name (str, optional):
 path to an SSM store parameter to receive the generated private key, instead of importing it or storing it locally. ssm_key_id (str, optional):
 ID of a KMS key to encrypt the SSM parameter with. If omitted, the default key will be used. public_key_path (str, optional):
 path to a public key file to be imported instead of generating a new key. Incompatible with the SSM options, as the private key will not be available for storing. Returns: In case of failure ``False``, otherwise a dict containing: status (str):
 one of "exists", "imported" or "created" key_name (str):
 name of the key pair fingerprint (str):
 fingerprint of the key pair file_path (str, optional):
 if a new key was created, the path to the file where the private key was stored """


    keypair_name = kwargs["keypair"]
    ssm_parameter_name = kwargs.get("ssm_parameter_name")
    ssm_key_id = kwargs.get("ssm_key_id")
    public_key_path = kwargs.get("public_key_path")

    if public_key_path and ssm_parameter_name:
        logger.error("public_key_path and ssm_parameter_name cannot be "
                     "specified at the same time")
        return False

    session = get_session(region=provider.region,
                          profile=kwargs.get("profile"))
    ec2 = session.client("ec2")

    keypair = get_existing_key_pair(ec2, keypair_name)
    if keypair:
        return keypair

    if public_key_path:
        keypair = create_key_pair_from_public_key_file(
            ec2, keypair_name, public_key_path)

    elif ssm_parameter_name:
        ssm = session.client('ssm')
        keypair = create_key_pair_in_ssm(
            ec2, ssm, keypair_name, ssm_parameter_name, ssm_key_id)
    else:
        action, path = interactive_prompt(keypair_name)
        if action == "import":
            keypair = create_key_pair_from_public_key_file(
                ec2, keypair_name, path)
        elif action == "create":
            keypair = create_key_pair_local(ec2, keypair_name, path)
        else:
            logger.warning("no action to find keypair, failing")

    if not keypair:
        return False

    return keypair