Skip to content

delete_key_pair async

delete_key_pair(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    key_name: Optional[KeyPairNameWithResolver] = None,
    key_pair_id: Optional[KeyPairId] = None,
    dry_run: Optional[Boolean] = None,
) -> DeleteKeyPairResult

Deletes the specified key pair, by removing the public key from Amazon EC2.

Parameters:

  • key_name (Optional[KeyPairNameWithResolver], default: None ) –

    The name of the key pair.

  • key_pair_id (Optional[KeyPairId], default: None ) –

    The ID of the key pair.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

Raises:

Examples:

To delete a key pair This example deletes the specified key pair.

>>> await client.delete_key_pair(key_name='my-key-pair')
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def delete_key_pair(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    key_name: Optional[
        "capo_ec2.types.key_pair_name_with_resolver.KeyPairNameWithResolver"
    ] = None,
    key_pair_id: Optional["capo_ec2.types.key_pair_id.KeyPairId"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.delete_key_pair_result.DeleteKeyPairResult":
    """<p>Deletes the specified key pair, by removing the public key from Amazon EC2.</p>

    Args:
        key_name: <p>The name of the key pair.</p>
        key_pair_id: <p>The ID of the key pair.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To delete a key pair
        This example deletes the specified key pair.

        >>> await client.delete_key_pair(key_name='my-key-pair')
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.delete_key_pair_request.DeleteKeyPairRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.delete_key_pair_result.DeleteKeyPairResult"
    ]:
        import capo_ec2._operations.amazon_ec2.delete_key_pair

        (
            output,
            http_response,
        ) = await capo_ec2._operations.amazon_ec2.delete_key_pair.async_delete_key_pair(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DeleteKeyPair")
    )
    input_: capo_ec2.types.delete_key_pair_request.DeleteKeyPairRequest = {}
    if key_name is not None:
        input_["key_name"] = key_name
    if key_pair_id is not None:
        input_["key_pair_id"] = key_pair_id
    if dry_run is not None:
        input_["dry_run"] = dry_run

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output