/AWS1/IF_KMS=>GETKEYLASTUSAGE()¶
About GetKeyLastUsage¶
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.
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.
Method Signature¶
METHODS /AWS1/IF_KMS~GETKEYLASTUSAGE
IMPORTING
!IV_KEYID TYPE /AWS1/KMSKEYIDTYPE OPTIONAL
RETURNING
VALUE(OO_OUTPUT) TYPE REF TO /aws1/cl_kmsgetkeylastusagersp
RAISING
/AWS1/CX_KMSDEPENDENCYTMOUTEX
/AWS1/CX_KMSINVALIDARNEX
/AWS1/CX_KMSKMSINTERNALEX
/AWS1/CX_KMSNOTFOUNDEXCEPTION
/AWS1/CX_KMSCLIENTEXC
/AWS1/CX_KMSSERVEREXC
/AWS1/CX_RT_TECHNICAL_GENERIC
/AWS1/CX_RT_SERVICE_GENERIC.
IMPORTING¶
Required arguments:¶
iv_keyid TYPE /AWS1/KMSKEYIDTYPE /AWS1/KMSKEYIDTYPE¶
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-1234567890abKey ARN:
arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890abTo get the key ID and key ARN for a KMS key, use ListKeys or DescribeKey.
RETURNING¶
oo_output TYPE REF TO /aws1/cl_kmsgetkeylastusagersp /AWS1/CL_KMSGETKEYLASTUSAGERSP¶
Examples¶
Syntax Example¶
This is an example of the syntax for calling the method. It includes every possible argument and initializes every possible value. The data provided is not necessarily semantically accurate (for example the value "string" may be provided for something that is intended to be an instance ID, or in some cases two arguments may be mutually exclusive). The syntax shows the ABAP syntax for creating the various data structures.
DATA(lo_result) = lo_client->getkeylastusage( |string| ).
This is an example of reading all possible response values
lo_result = lo_result.
IF lo_result IS NOT INITIAL.
lv_keyidtype = lo_result->get_keyid( ).
lo_keylastusagedata = lo_result->get_keylastusage( ).
IF lo_keylastusagedata IS NOT INITIAL.
lv_keylastusagetrackingope = lo_keylastusagedata->get_operation( ).
lv_datetype = lo_keylastusagedata->get_timestamp( ).
lv_cloudtraileventidtype = lo_keylastusagedata->get_cloudtraileventid( ).
lv_kmsrequestidtype = lo_keylastusagedata->get_kmsrequestid( ).
ENDIF.
lv_datetype = lo_result->get_trackingstartdate( ).
lv_datetype = lo_result->get_keycreationdate( ).
ENDIF.
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.
DATA(lo_result) = lo_client->getkeylastusage( |1234abcd-12ab-34cd-56ef-1234567890ab| ).