get_key_last_usage¶
Operation¶
get_key_last_usage
async
¶
get_key_last_usage(input: GetKeyLastUsageInput, plugins: list[Plugin] | None = None) -> GetKeyLastUsageOutput
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 GetKeyLastUsage 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
KeyLastUsageresponse element is present, the key has been used for a successful cryptographic operation since theTrackingStartDate. The response includes the operation type, timestamp, and associated CloudTrail event ID. -
If the
KeyLastUsageresponse element is empty andKeyCreationDateis on or afterTrackingStartDate, the key has not been used for a successful cryptographic operation since it was created. -
If the
KeyLastUsageresponse element is empty andKeyCreationDateis beforeTrackingStartDate, there is no record of the key being used for a successful cryptographic operation since theTrackingStartDate. However, the key may have been used before tracking began. To determine whether the key was used before theTrackingStartDate, 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 ReEncrypt 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.
Note
Do not use GetKeyLastUsage 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. CloudTrail remains the authoritative source
for all API calls made to your key.
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:
-
DescribeKey
-
DisableKey
-
ScheduleKeyDeletion
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
GetKeyLastUsageInput
|
An instance of |
required |
plugins
|
list[Plugin] | None
|
A list of callables that modify the configuration dynamically. Changes made by these plugins only apply for the duration of the operation execution and will not affect any other operation invocations. |
None
|
Returns:
| Type | Description |
|---|---|
GetKeyLastUsageOutput
|
An instance of |
Input¶
GetKeyLastUsageInput
dataclass
¶
Bases: _SerdeShape
Dataclass for GetKeyLastUsageInput structure.
Attributes¶
key_id
class-attribute
instance-attribute
¶
key_id: str | None = ...
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 ListKeys or DescribeKey.
Output¶
GetKeyLastUsageOutput
dataclass
¶
Bases: _SerdeShape
Dataclass for GetKeyLastUsageOutput structure.
Attributes¶
key_creation_date
class-attribute
instance-attribute
¶
key_creation_date: datetime | None = ...
The date and time when the KMS key was created.
key_id
class-attribute
instance-attribute
¶
key_id: str | None = ...
The globally unique identifier for the KMS key.
key_last_usage
class-attribute
instance-attribute
¶
key_last_usage: KeyLastUsageData | None = ...
Contains usage information about the last time the KMS key was used for a successful cryptographic operation. If the key has not been used since tracking began, this response element is an empty object.
response_metadata
class-attribute
instance-attribute
¶
Metadata about the response that produced this output. Use this to recover the request identifiers a service's support team needs in order to investigate a call. Members of the metadata are individually optional.