Skip to content

Get Key Last Usage

kms_get_key_last_usage R Documentation

Returns usage information about the last successful cryptographic operation performed with a specified KMS key, including the operation type, timestamp, and associated CloudTrail event ID

Description

Returns usage information about the last successful cryptographic operation performed with a specified KMS key, including the operation type, timestamp, and associated CloudTrail event ID.

The TrackingStartDate in the get_key_last_usage response indicates the date from which KMS began recording cryptographic activity for a given key. Use this value together with KeyCreationDate to understand the key's usage history:

  • If the KeyLastUsage response element is present, the key has been used for a successful cryptographic operation since the TrackingStartDate. The response includes the operation type, timestamp, and associated CloudTrail event ID.

  • If the KeyLastUsage response element is empty and KeyCreationDate is on or after TrackingStartDate, the key has not been used for a successful cryptographic operation since it was created.

  • If the KeyLastUsage response element is empty and KeyCreationDate is before TrackingStartDate, there is no record of the key being used for a successful cryptographic operation since the TrackingStartDate. However, the key may have been used before tracking began. To determine whether the key was used before the TrackingStartDate, examine your past CloudTrail logs.

For multi-Region KMS keys, primary and replica keys track last usage independently. Each key in a multi-Region key set maintains its own usage information.

The re_encrypt operation uses two keys: a source key for decryption and a destination key for encryption. Usage information is recorded for both keys independently, each with the CloudTrail event ID from the respective key owner's account.

Do not use get_key_last_usage as the sole indicator when scheduling a key for deletion. Instead, first disable the key and monitor CloudTrail for DisabledException entries, as there could be infrequent workflows that are dependent on the key. By looking for this exception, you can identify potential dependencies and workload failures before they occur.

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

Required permissions: kms:GetKeyLastUsage (key policy)

Related operations:

  • describe_key

  • disable_key

  • schedule_key_deletion

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

Usage

kms_get_key_last_usage(KeyId)

Arguments

KeyId

[required] Identifies the KMS key to get usage information for. To specify a KMS key, use its key ID or key ARN. Alias names are not supported.

Specify the key ID or key ARN of the KMS key.

For example:

  • Key ID: ⁠1234abcd-12ab-34cd-56ef-1234567890ab⁠

  • Key ARN: ⁠arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab⁠

To get the key ID and key ARN for a KMS key, use list_keys or describe_key.

Value

A list with the following syntax:

list(
  KeyId = "string",
  KeyLastUsage = list(
    Operation = "Decrypt"|"DeriveSharedSecret"|"Encrypt"|"GenerateDataKey"|"GenerateDataKeyPair"|"GenerateDataKeyPairWithoutPlaintext"|"GenerateDataKeyWithoutPlaintext"|"GenerateMac"|"ReEncrypt"|"Sign"|"Verify"|"VerifyMac",
    Timestamp = as.POSIXct(
      "2015-01-01"
    ),
    CloudTrailEventId = "string",
    KmsRequestId = "string"
  ),
  TrackingStartDate = as.POSIXct(
    "2015-01-01"
  ),
  KeyCreationDate = as.POSIXct(
    "2015-01-01"
  )
)

Request syntax

svc$get_key_last_usage(
  KeyId = "string"
)