Skip to content

list_grants async

list_grants(
    key_id: KeyIdType,
    *,
    config_overrides: Optional[AsyncKMSClientConfig] = None,
    limit: Optional[LimitType] = None,
    marker: Optional[MarkerType] = None,
    grant_id: Optional[GrantIdType] = None,
    grantee_principal: Optional[PrincipalIdType] = None,
    grantee_service_principal: Optional[ServicePrincipalType] = None,
) -> ListGrantsResponse

Gets a list of all grants for the specified KMS key.

You must specify the KMS key in all requests. You can filter the grant list by grant ID, grantee principal, or grantee service principal.

For detailed information about grants, including grant terminology, see Grants in KMS in the Key Management Service Developer Guide . For examples of creating grants in several programming languages, see Use CreateGrant with an Amazon Web Services SDK or CLI.

When a grant is created with the GranteePrincipal field, the ListGrants response usually contains the user or role designated as the grantee principal in the grant. However, if the grantee principal is an Amazon Web Services service, the GranteePrincipal field contains an Amazon Web Services service principal, which might correspond to several different grantee principals, such as an IAM user, IAM role, or Amazon Web Services account.

When a grant is created with the GranteeServicePrincipal field, the ListGrants response always includes a GranteeServicePrincipal that indicates the grantee is actually an Amazon Web Services service principal.

Cross-account use: Yes. To perform this operation on a KMS key in a different Amazon Web Services account, specify the key ARN in the value of the KeyId parameter.

Required permissions: kms:ListGrants (key policy)

Related operations:

Eventual consistency: The KMS API follows an eventual consistency model. For more information, see KMS eventual consistency.

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 100, inclusive. If you do not include a value, it defaults to 50.

  • 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.

  • key_id (KeyIdType) –

    Returns only grants for the specified KMS key. This parameter is required.

    Specify the key ID or key ARN of the KMS key. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN.

    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.

  • grant_id (Optional[GrantIdType], default: None ) –

    Returns only the grant with the specified grant ID. The grant ID uniquely identifies the grant.

  • grantee_principal (Optional[PrincipalIdType], default: None ) –

    Returns only grants where the specified principal is the grantee principal for the grant.

    You can specify either GranteePrincipal or GranteeServicePrincipal, but not both.

  • grantee_service_principal (Optional[ServicePrincipalType], default: None ) –

    Returns only grants where the specified Amazon Web Services service principal is the grantee service principal for the grant. This filter is only usable by callers in a service principal.

    You can specify either GranteePrincipal or GranteeServicePrincipal, but not both.

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.

  • InvalidGrantIdException –

    The request was rejected because the specified GrantId is not valid.

  • 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.

  • KMSInvalidStateException –

    The request was rejected because the state of the specified resource is not valid for this request.

    This exceptions means one of the following:

    • The key state of the KMS key is not compatible with the operation.

      To find the key state, use the DescribeKey operation. For more information about which key states are compatible with each KMS operation, see Key states of KMS keys in the Key Management Service Developer Guide .

    • For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.

  • 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.

Source code in docs_src/capo_kms/_services/async_kms.py
async def list_grants(
    self,
    key_id: "capo_kms.types.key_id_type.KeyIdType",
    *,
    config_overrides: Optional[AsyncKMSClientConfig] = None,
    limit: Optional["capo_kms.types.limit_type.LimitType"] = None,
    marker: Optional["capo_kms.types.marker_type.MarkerType"] = None,
    grant_id: Optional["capo_kms.types.grant_id_type.GrantIdType"] = None,
    grantee_principal: Optional[
        "capo_kms.types.principal_id_type.PrincipalIdType"
    ] = None,
    grantee_service_principal: Optional[
        "capo_kms.types.service_principal_type.ServicePrincipalType"
    ] = None,
) -> "capo_kms.types.list_grants_response.ListGrantsResponse":
    """<p>Gets a list of all grants for the specified KMS key. </p> <p>You must specify the KMS key in all requests. You can filter the grant list by grant ID, grantee principal, or grantee service principal.</p> <p>For detailed information about grants, including grant terminology, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/grants.html">Grants in KMS</a> in the <i> <i>Key Management Service Developer Guide</i> </i>. For examples of creating grants in several programming languages, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/example_kms_CreateGrant_section.html">Use CreateGrant with an Amazon Web Services SDK or CLI</a>. </p> <note> <p>When a grant is created with the <code>GranteePrincipal</code> field, the <code>ListGrants</code> response usually contains the user or role designated as the grantee principal in the grant. However, if the grantee principal is an Amazon Web Services service, the <code>GranteePrincipal</code> field contains an Amazon Web Services <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services">service principal</a>, which might correspond to several different grantee principals, such as an IAM user, IAM role, or Amazon Web Services account.</p> <p>When a grant is created with the <code>GranteeServicePrincipal</code> field, the <code>ListGrants</code> response always includes a <code>GranteeServicePrincipal</code> that indicates the grantee is actually an Amazon Web Services <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_principal.html#principal-services">service principal</a>.</p> </note> <p> <b>Cross-account use</b>: Yes. To perform this operation on a KMS key in a different Amazon Web Services account, specify the key ARN in the value of the <code>KeyId</code> parameter.</p> <p> <b>Required permissions</b>: <a href="https://docs.aws.amazon.com/kms/latest/developerguide/kms-api-permissions-reference.html">kms:ListGrants</a> (key policy)</p> <p> <b>Related operations:</b> </p> <ul> <li> <p> <a>CreateGrant</a> </p> </li> <li> <p> <a>ListRetirableGrants</a> </p> </li> <li> <p> <a>RetireGrant</a> </p> </li> <li> <p> <a>RevokeGrant</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:
        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 100, inclusive. If you do not include a value, it defaults to 50.</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>
        key_id: <p>Returns only grants for the specified KMS key. This parameter is required.</p> <p>Specify the key ID or key ARN of the KMS key. To specify a KMS key in a different Amazon Web Services account, you must use the key ARN.</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>
        grant_id: <p>Returns only the grant with the specified grant ID. The grant ID uniquely identifies the grant. </p>
        grantee_principal: <p>Returns only grants where the specified principal is the grantee principal for the grant.</p> <p>You can specify either <code>GranteePrincipal</code> or <code>GranteeServicePrincipal</code>, but not both.</p>
        grantee_service_principal: <p>Returns only grants where the specified Amazon Web Services service principal is the grantee service principal for the grant. This filter is only usable by callers in a service principal.</p> <p>You can specify either <code>GranteePrincipal</code> or <code>GranteeServicePrincipal</code>, but not both.</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.invalid_grant_id_exception.InvalidGrantIdException: <p>The request was rejected because the specified <code>GrantId</code> is not valid.</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.kms_invalid_state_exception.KMSInvalidStateException: <p>The request was rejected because the state of the specified resource is not valid for this request.</p> <p>This exceptions means one of the following:</p> <ul> <li> <p>The key state of the KMS key is not compatible with the operation. </p> <p>To find the key state, use the <a>DescribeKey</a> operation. For more information about which key states are compatible with each KMS operation, see <a href="https://docs.aws.amazon.com/kms/latest/developerguide/key-state.html">Key states of KMS keys</a> in the <i> <i>Key Management Service Developer Guide</i> </i>.</p> </li> <li> <p>For cryptographic operations on KMS keys in custom key stores, this exception represents a general failure with many possible causes. To identify the cause, see the error message that accompanies the exception.</p> </li> </ul>
        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.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_kms.types.list_grants_request.ListGrantsRequest]",
    ) -> AsyncOperationResponse[
        "capo_kms.types.list_grants_response.ListGrantsResponse"
    ]:
        import capo_kms._operations.trent_service.list_grants

        (
            output,
            http_response,
        ) = await capo_kms._operations.trent_service.list_grants.async_list_grants(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("ListGrants")
    )
    input_: capo_kms.types.list_grants_request.ListGrantsRequest = {
        "key_id": key_id
    }
    if limit is not None:
        input_["limit"] = limit
    if marker is not None:
        input_["marker"] = marker
    if grant_id is not None:
        input_["grant_id"] = grant_id
    if grantee_principal is not None:
        input_["grantee_principal"] = grantee_principal
    if grantee_service_principal is not None:
        input_["grantee_service_principal"] = grantee_service_principal

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output