getKeyLastUsage method
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.
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.
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.May throw DependencyTimeoutException.
May throw InvalidArnException.
May throw KMSInternalException.
May throw NotFoundException.
Parameter keyId :
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
Implementation
Future<GetKeyLastUsageResponse> getKeyLastUsage({
required String keyId,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'TrentService.GetKeyLastUsage'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'KeyId': keyId,
},
);
return GetKeyLastUsageResponse.fromJson(jsonResponse.body);
}