KMS / Client / list_keys

list_keys#

KMS.Client.list_keys(**kwargs)#

Gets a list of all KMS keys in the caller’s Amazon Web Services account and Region.

Cross-account use: No. You cannot perform this operation on a KMS key in a different Amazon Web Services account.

Required permissions: kms:ListKeys (IAM policy)

Related operations:

  • CreateKey

  • DescribeKey

  • ListAliases

  • ListResourceTags

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

See also: AWS API Documentation

Request Syntax

response = client.list_keys(
    Limit=123,
    Marker='string'
)
Parameters:
  • Limit (integer) –

    Use this parameter to specify the maximum number of items to return. When this value is present, KMS does not return more than the specified number of items, but it might return fewer.

    This value is optional. If you include a value, it must be between 1 and 1000, inclusive. If you do not include a value, it defaults to 100.

  • Marker (string) – Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.

Return type:

dict

Returns:

Response Syntax

{
    'Keys': [
        {
            'KeyId': 'string',
            'KeyArn': 'string'
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) –

    • Keys (list) –

      A list of KMS keys.

      • (dict) –

        Contains information about each entry in the key list.

        • KeyId (string) –

          Unique identifier of the key.

        • KeyArn (string) –

          ARN of the key.

    • NextMarker (string) –

      When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

    • Truncated (boolean) –

      A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in this response to the Marker parameter in a subsequent request.

Exceptions

Examples

The following example lists KMS keys.

response = client.list_keys(
)

print(response)

Expected Output:

{
    # A list of KMS keys, including the key ID and Amazon Resource Name (ARN) of each one.
    'Keys': [
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/0d990263-018e-4e65-a703-eff731de951e',
            'KeyId': '0d990263-018e-4e65-a703-eff731de951e',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/144be297-0ae1-44ac-9c8f-93cd8c82f841',
            'KeyId': '144be297-0ae1-44ac-9c8f-93cd8c82f841',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/21184251-b765-428e-b852-2c7353e72571',
            'KeyId': '21184251-b765-428e-b852-2c7353e72571',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/214fe92f-5b03-4ae1-b350-db2a45dbe10c',
            'KeyId': '214fe92f-5b03-4ae1-b350-db2a45dbe10c',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/339963f2-e523-49d3-af24-a0fe752aa458',
            'KeyId': '339963f2-e523-49d3-af24-a0fe752aa458',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/b776a44b-df37-4438-9be4-a27494e4271a',
            'KeyId': 'b776a44b-df37-4438-9be4-a27494e4271a',
        },
        {
            'KeyArn': 'arn:aws:kms:us-east-2:111122223333:key/deaf6c9e-cf2c-46a6-bf6d-0b6d487cffbb',
            'KeyId': 'deaf6c9e-cf2c-46a6-bf6d-0b6d487cffbb',
        },
    ],
    # A boolean that indicates whether there are more items in the list. Returns true when there are more items, or false when there are not.
    'Truncated': False,
    'ResponseMetadata': {
        '...': '...',
    },
}