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 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 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.
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.
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:
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
Parameters:
-
key_id
(KeyIdType)
–
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:
To get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey.
Raises:
-
DependencyTimeoutException
–
The system timed out while trying to fulfill the request. You can retry the request.
-
InvalidArnException
–
The request was rejected because a specified ARN, or an ARN in a key policy, is not valid.
-
KMSInternalException
–
The request was rejected because an internal exception occurred. The request can be retried.
-
NotFoundException
–
The request was rejected because the specified entity or resource could not be found.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To retrieve the last usage for a KMS key
The following example retrieves usage information about the last successful cryptographic operation performed with the specified KMS key, including the operation type, timestamp, and associated AWS CloudTrail event ID.
>>> await client.get_key_last_usage(key_id='1234abcd-12ab-34cd-56ef-1234567890ab')
Source code in docs_src/capo_kms/_services/async_kms.py
| async def get_key_last_usage(
self,
key_id: "capo_kms.types.key_id_type.KeyIdType",
*,
config_overrides: Optional[AsyncKMSClientConfig] = None,
) -> "capo_kms.types.get_key_last_usage_response.GetKeyLastUsageResponse":
"""<p>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.</p> <p>The <code>TrackingStartDate</code> in the <code>GetKeyLastUsage</code> response indicates the date from which KMS began recording cryptographic activity for a given key. Use this value together with <code>KeyCreationDate</code> to understand the key's usage history:</p> <ul> <li> <p>If the <code>KeyLastUsage</code> response element is <i>present</i>, the key has been used for a successful cryptographic operation since the <code>TrackingStartDate</code>. The response includes the operation type, timestamp, and associated CloudTrail event ID.</p> </li> <li> <p>If the <code>KeyLastUsage</code> response element is <i>empty</i> and <code>KeyCreationDate</code> is on or after <code>TrackingStartDate</code>, the key has not been used for a successful cryptographic operation since it was created.</p> </li> <li> <p>If the <code>KeyLastUsage</code> response element is <i>empty</i> and <code>KeyCreationDate</code> is before <code>TrackingStartDate</code>, there is no record of the key being used for a successful cryptographic operation since the <code>TrackingStartDate</code>. However, the key may have been used before tracking began. To determine whether the key was used before the <code>TrackingStartDate</code>, examine your past CloudTrail logs.</p> </li> </ul> <p>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.</p> <p>The <code>ReEncrypt</code> 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.</p> <note> <p>Do not use <code>GetKeyLastUsage</code> as the sole indicator when scheduling a key for deletion. Instead, first <a href="https://docs.aws.amazon.com/kms/latest/developerguide/enabling-keys.html">disable the key</a> and monitor CloudTrail for <code>DisabledException</code> 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.</p> </note> <p> <b>Cross-account use</b>: No. You cannot perform this operation on a KMS key in a different Amazon Web Services account.</p> <p> <b>Required permissions</b>: <a href="https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html">kms:GetKeyLastUsage</a> (key policy)</p> <p> <b>Related operations:</b> </p> <ul> <li> <p> <a>DescribeKey</a> </p> </li> <li> <p> <a>DisableKey</a> </p> </li> <li> <p> <a>ScheduleKeyDeletion</a> </p> </li> </ul> <p> <b>Eventual consistency</b>: The KMS API follows an eventual consistency model. For more information, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/accessing-kms.html#programming-eventual-consistency">KMS eventual consistency</a>.</p>
Args:
key_id: <p>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.</p> <p>Specify the key ID or key ARN of the KMS key.</p> <p>For example:</p> <ul> <li> <p>Key ID: <code>1234abcd-12ab-34cd-56ef-1234567890ab</code> </p> </li> <li> <p>Key ARN: <code>arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab</code> </p> </li> </ul> <p>To get the key ID and key ARN for a KMS key, use <a>ListKeys</a> or <a>DescribeKey</a>.</p>
Raises:
capo_kms.errors.dependency_timeout_exception.DependencyTimeoutException: <p>The system timed out while trying to fulfill the request. You can retry the request.</p>
capo_kms.errors.invalid_arn_exception.InvalidArnException: <p>The request was rejected because a specified ARN, or an ARN in a key policy, is not valid.</p>
capo_kms.errors.kms_internal_exception.KMSInternalException: <p>The request was rejected because an internal exception occurred. The request can be retried.</p>
capo_kms.errors.not_found_exception.NotFoundException: <p>The request was rejected because the specified entity or resource could not be found.</p>
capo_kms.errors.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To retrieve the last usage for a KMS key
The following example retrieves usage information about the last successful cryptographic operation performed with the specified KMS key, including the operation type, timestamp, and associated AWS CloudTrail event ID.
>>> await client.get_key_last_usage(key_id='1234abcd-12ab-34cd-56ef-1234567890ab')
"""
async def _handler(
req: "AsyncOperationRequest[capo_kms.types.get_key_last_usage_request.GetKeyLastUsageRequest]",
) -> AsyncOperationResponse[
"capo_kms.types.get_key_last_usage_response.GetKeyLastUsageResponse"
]:
import capo_kms._operations.trent_service.get_key_last_usage
(
output,
http_response,
) = await capo_kms._operations.trent_service.get_key_last_usage.async_get_key_last_usage(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("GetKeyLastUsage")
)
input_: capo_kms.types.get_key_last_usage_request.GetKeyLastUsageRequest = {
"key_id": key_id
}
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|