Skip to content

describe_key_pairs async

describe_key_pairs(
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    key_names: Optional[KeyNameStringList] = None,
    key_pair_ids: Optional[KeyPairIdStringList] = None,
    include_public_key: Optional[Boolean] = None,
    dry_run: Optional[Boolean] = None,
    filters: Optional[FilterList] = None,
) -> DescribeKeyPairsResult

Describes the specified key pairs or all of your key pairs.

For more information about key pairs, see Amazon EC2 key pairs in the Amazon EC2 User Guide.

Parameters:

  • key_names (Optional[KeyNameStringList], default: None ) –

    The key pair names.

    Default: Describes all of your key pairs.

  • key_pair_ids (Optional[KeyPairIdStringList], default: None ) –

    The IDs of the key pairs.

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

    If true, the public key material is included in the response.

    Default: false

  • 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.

  • filters (Optional[FilterList], default: None ) –

    The filters.

    • key-pair-id - The ID of the key pair.

    • fingerprint - The fingerprint of the key pair.

    • key-name - The name of the key pair.

    • tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.

    • tag: - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value.

Raises:

Examples:

To display a key pair This example displays the fingerprint for the specified key.

>>> await client.describe_key_pairs(key_names=['my-key-pair'])
Source code in docs_src/capo_ec2/_services/async_ec2.py
async def describe_key_pairs(
    self,
    *,
    config_overrides: Optional[AsyncEC2ClientConfig] = None,
    key_names: Optional[
        "capo_ec2.types.key_name_string_list.KeyNameStringList"
    ] = None,
    key_pair_ids: Optional[
        "capo_ec2.types.key_pair_id_string_list.KeyPairIdStringList"
    ] = None,
    include_public_key: Optional["capo_ec2.types.boolean.Boolean"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    filters: Optional["capo_ec2.types.filter_list.FilterList"] = None,
) -> "capo_ec2.types.describe_key_pairs_result.DescribeKeyPairsResult":
    """<p>Describes the specified key pairs or all of your key pairs.</p> <p>For more information about key pairs, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html">Amazon EC2 key pairs</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        key_names: <p>The key pair names.</p> <p>Default: Describes all of your key pairs.</p>
        key_pair_ids: <p>The IDs of the key pairs.</p>
        include_public_key: <p>If <code>true</code>, the public key material is included in the response.</p> <p>Default: <code>false</code> </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>
        filters: <p>The filters.</p> <ul> <li> <p> <code>key-pair-id</code> - The ID of the key pair.</p> </li> <li> <p> <code>fingerprint</code> - The fingerprint of the key pair.</p> </li> <li> <p> <code>key-name</code> - The name of the key pair.</p> </li> <li> <p> <code>tag-key</code> - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.</p> </li> <li> <p> <code>tag</code>:<key> - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key <code>Owner</code> and the value <code>TeamA</code>, specify <code>tag:Owner</code> for the filter name and <code>TeamA</code> for the filter value.</p> </li> </ul>

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

    Examples:
        To display a key pair
        This example displays the fingerprint for the specified key.

        >>> await client.describe_key_pairs(key_names=['my-key-pair'])
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_ec2.types.describe_key_pairs_request.DescribeKeyPairsRequest]",
    ) -> AsyncOperationResponse[
        "capo_ec2.types.describe_key_pairs_result.DescribeKeyPairsResult"
    ]:
        import capo_ec2._operations.amazon_ec2.describe_key_pairs

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DescribeKeyPairs")
    )
    input_: capo_ec2.types.describe_key_pairs_request.DescribeKeyPairsRequest = {}
    if key_names is not None:
        input_["key_names"] = key_names
    if key_pair_ids is not None:
        input_["key_pair_ids"] = key_pair_ids
    if include_public_key is not None:
        input_["include_public_key"] = include_public_key
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if filters is not None:
        input_["filters"] = filters

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