Gets a list of all KMS keys in the caller's Amazon Web Services account and Region.
You can also use ListKeys to list KMS keys in the Region that other Amazon Web Services accounts shared with the caller's Amazon Web Services account through Resource Access Manager (RAM). To list them, use the ResourceOwners parameter. If you omit ResourceOwners, ListKeys lists only the KMS keys in the caller's Amazon Web Services account.
When ResourceOwners includes OTHER_ACCOUNTS_VIA_RAM, ListKeys returns the KMS keys that other Amazon Web Services accounts currently share with the caller's Amazon Web Services account through RAM. For information about how and when a resource that another account shares becomes available to your Amazon Web Services account, see Access Amazon Web Services resources shared with you in the RAM User Guide.
Cross-account use: No. This operation doesn't take a KMS key parameter, so you can't use it to list the KMS keys of a specific Amazon Web Services account. The only KMS keys in other Amazon Web Services accounts that ListKeys returns are the ones that other accounts shared with the caller's Amazon Web Services account through RAM. To list them, set the ResourceOwners parameter to include OTHER_ACCOUNTS_VIA_RAM.
Required permissions: kms:ListKeys (IAM policy)
The same kms:ListKeys permission lets you list the KMS keys that other accounts shared with you through RAM. KMS doesn't evaluate the key policies of shared KMS keys when it lists them. To use a shared KMS key, you need permission for each operation on that KMS key.
Related operations:
Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.
KMS keys that other Amazon Web Services accounts share with you can take some time to appear in or disappear from ListKeys results after changes to resource shares, such as accepting an invitation or deleting a resource share.
Parameters:
-
limit
(Optional[LimitType], default:
None
)
–
Use this parameter to specify the maximum number of items to return. When this value is present, KMS does not return more than the specified number of items, but it might return fewer.
This value is optional. If you include a value, it must be between 1 and 1000, inclusive. If you do not include a value, it defaults to 100.
-
marker
(Optional[MarkerType], default:
None
)
–
Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of NextMarker from the truncated response you just received.
-
resource_owners
(Optional[ResourceOwnersList], default:
None
)
–
Specifies whose KMS keys to list. Use this parameter to list KMS keys that other Amazon Web Services accounts shared with your Amazon Web Services account through Resource Access Manager (RAM).
Specify one or two values. Valid values are:
- SELF
-
Lists the KMS keys in your Amazon Web Services account and Region.
- OTHER_ACCOUNTS_VIA_RAM
-
Lists the KMS keys in the Region that other Amazon Web Services accounts currently share with your Amazon Web Services account through RAM. This list doesn't include KMS keys that your Amazon Web Services account owns. For each of these KMS keys, the key ARN in the response contains the account ID of the Amazon Web Services account that owns the KMS key.
If you omit this parameter, ListKeys lists only the KMS keys in your Amazon Web Services account. If you specify both values, in either order, ListKeys returns the KMS keys in your Amazon Web Services account first, and then the KMS keys that other Amazon Web Services accounts shared with you. A single response doesn't contain both kinds of KMS keys.
When ResourceOwners includes OTHER_ACCOUNTS_VIA_RAM, a response can contain fewer KMS keys than the Limit value, or none, even when Truncated is true. To get all of the KMS keys, continue calling ListKeys with the NextMarker value from each response until Truncated is false. Use a NextMarker value only in a request that has the same ResourceOwners value as the request that returned it. Otherwise, the request can fail with an InvalidMarkerException.
KMS keys that other Amazon Web Services accounts share with you can take some time to appear in or disappear from the results after changes to resource shares.
Raises:
-
DependencyTimeoutException
–
The system timed out while trying to fulfill the request. You can retry the request.
-
InvalidMarkerException
–
The request was rejected because the marker that specifies where pagination should next begin is not valid.
-
KMSInternalException
–
The request was rejected because an internal exception occurred. The request can be retried.
-
UnknownServiceError
–
The service returned an error code this client does not model.
Examples:
To list KMS keys
The following example lists KMS keys.
>>> await client.list_keys()
To list KMS keys that other accounts shared with you through AWS RAM
The following example lists the KMS keys in the Region that other AWS accounts shared with your AWS account through AWS Resource Access Manager (AWS RAM).
>>> await client.list_keys(resource_owners=['OTHER_ACCOUNTS_VIA_RAM'])
Source code in docs_src/capo_kms/_services/async_kms.py
| async def list_keys(
self,
*,
config_overrides: Optional[AsyncKMSClientConfig] = None,
limit: Optional["capo_kms.types.limit_type.LimitType"] = None,
marker: Optional["capo_kms.types.marker_type.MarkerType"] = None,
resource_owners: Optional[
"capo_kms.types.resource_owners_list.ResourceOwnersList"
] = None,
) -> "capo_kms.types.list_keys_response.ListKeysResponse":
"""<p>Gets a list of all KMS keys in the caller's Amazon Web Services account and Region.</p> <p>You can also use <code>ListKeys</code> to list KMS keys in the Region that other Amazon Web Services accounts shared with the caller's Amazon Web Services account through Resource Access Manager (RAM). To list them, use the <code>ResourceOwners</code> parameter. If you omit <code>ResourceOwners</code>, <code>ListKeys</code> lists only the KMS keys in the caller's Amazon Web Services account.</p> <p>When <code>ResourceOwners</code> includes <code>OTHER_ACCOUNTS_VIA_RAM</code>, <code>ListKeys</code> returns the KMS keys that other Amazon Web Services accounts currently share with the caller's Amazon Web Services account through RAM. For information about how and when a resource that another account shares becomes available to your Amazon Web Services account, see <a href="https://docs.aws.amazon.com/ram/latest/userguide/working-with-shared.html">Access Amazon Web Services resources shared with you</a> in the <i>RAM User Guide</i>.</p> <p> <b>Cross-account use</b>: No. This operation doesn't take a KMS key parameter, so you can't use it to list the KMS keys of a specific Amazon Web Services account. The only KMS keys in other Amazon Web Services accounts that <code>ListKeys</code> returns are the ones that other accounts shared with the caller's Amazon Web Services account through RAM. To list them, set the <code>ResourceOwners</code> parameter to include <code>OTHER_ACCOUNTS_VIA_RAM</code>.</p> <p> <b>Required permissions</b>: <a href="https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html">kms:ListKeys</a> (IAM policy)</p> <p>The same <code>kms:ListKeys</code> permission lets you list the KMS keys that other accounts shared with you through RAM. KMS doesn't evaluate the key policies of shared KMS keys when it lists them. To use a shared KMS key, you need permission for each operation on that KMS key.</p> <p> <b>Related operations:</b> </p> <ul> <li> <p> <a>CreateKey</a> </p> </li> <li> <p> <a>DescribeKey</a> </p> </li> <li> <p> <a>ListAliases</a> </p> </li> <li> <p> <a>ListResourceTags</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> <p>KMS keys that other Amazon Web Services accounts share with you can take some time to appear in or disappear from <code>ListKeys</code> results after changes to resource shares, such as accepting an invitation or deleting a resource share.</p>
Args:
limit: <p>Use this parameter to specify the maximum number of items to return. When this value is present, KMS does not return more than the specified number of items, but it might return fewer.</p> <p>This value is optional. If you include a value, it must be between 1 and 1000, inclusive. If you do not include a value, it defaults to 100.</p>
marker: <p>Use this parameter in a subsequent request after you receive a response with truncated results. Set it to the value of <code>NextMarker</code> from the truncated response you just received.</p>
resource_owners: <p>Specifies whose KMS keys to list. Use this parameter to list KMS keys that other Amazon Web Services accounts shared with your Amazon Web Services account through Resource Access Manager (RAM).</p> <p>Specify one or two values. Valid values are:</p> <dl> <dt>SELF</dt> <dd> <p>Lists the KMS keys in your Amazon Web Services account and Region.</p> </dd> <dt>OTHER_ACCOUNTS_VIA_RAM</dt> <dd> <p>Lists the KMS keys in the Region that other Amazon Web Services accounts currently share with your Amazon Web Services account through RAM. This list doesn't include KMS keys that your Amazon Web Services account owns. For each of these KMS keys, the key ARN in the response contains the account ID of the Amazon Web Services account that owns the KMS key.</p> </dd> </dl> <p>If you omit this parameter, <code>ListKeys</code> lists only the KMS keys in your Amazon Web Services account. If you specify both values, in either order, <code>ListKeys</code> returns the KMS keys in your Amazon Web Services account first, and then the KMS keys that other Amazon Web Services accounts shared with you. A single response doesn't contain both kinds of KMS keys.</p> <p>When <code>ResourceOwners</code> includes <code>OTHER_ACCOUNTS_VIA_RAM</code>, a response can contain fewer KMS keys than the <code>Limit</code> value, or none, even when <code>Truncated</code> is true. To get all of the KMS keys, continue calling <code>ListKeys</code> with the <code>NextMarker</code> value from each response until <code>Truncated</code> is false. Use a <code>NextMarker</code> value only in a request that has the same <code>ResourceOwners</code> value as the request that returned it. Otherwise, the request can fail with an <code>InvalidMarkerException</code>.</p> <p>KMS keys that other Amazon Web Services accounts share with you can take some time to appear in or disappear from the results after changes to resource shares.</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_marker_exception.InvalidMarkerException: <p>The request was rejected because the marker that specifies where pagination should next begin 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.UnknownServiceError: The service returned an error code this client does not model.
Examples:
To list KMS keys
The following example lists KMS keys.
>>> await client.list_keys()
To list KMS keys that other accounts shared with you through AWS RAM
The following example lists the KMS keys in the Region that other AWS accounts shared with your AWS account through AWS Resource Access Manager (AWS RAM).
>>> await client.list_keys(resource_owners=['OTHER_ACCOUNTS_VIA_RAM'])
"""
async def _handler(
req: "AsyncOperationRequest[capo_kms.types.list_keys_request.ListKeysRequest]",
) -> AsyncOperationResponse[
"capo_kms.types.list_keys_response.ListKeysResponse"
]:
import capo_kms._operations.trent_service.list_keys
(
output,
http_response,
) = await capo_kms._operations.trent_service.list_keys.async_list_keys(
req.options, req.input
)
return AsyncOperationResponse(output=output, response=http_response)
interceptors_, options_ = self.operation_options(
config_overrides, OperationLogging("ListKeys")
)
input_: capo_kms.types.list_keys_request.ListKeysRequest = {}
if limit is not None:
input_["limit"] = limit
if marker is not None:
input_["marker"] = marker
if resource_owners is not None:
input_["resource_owners"] = resource_owners
response = await aexecute_pipeline(
AsyncOperationRequest(input=input_, options=options_),
handler=_handler,
interceptors=list(interceptors_),
)
await response.response.aclose()
return response.output
|