ListGrantsCommand

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 or grantee principal.

For detailed information about grants, including grant terminology, see Grants in KMS  in the Key Management Service Developer Guide . For examples of working with grants in several programming languages, see Programming grants .

The GranteePrincipal field in the ListGrants response usually contains the user or role designated as the grantee principal in the grant. However, when the grantee principal in the grant is an Amazon Web Services service, the GranteePrincipal field contains the service principal , which might represent several different grantee principals.

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:

  • CreateGrant

  • ListRetirableGrants

  • RetireGrant

  • RevokeGrant

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

Example Syntax

Use a bare-bones client and the command you need to make an API call.

import { KMSClient, ListGrantsCommand } from "@aws-sdk/client-kms"; // ES Modules import
// const { KMSClient, ListGrantsCommand } = require("@aws-sdk/client-kms"); // CommonJS import
const client = new KMSClient(config);
const input = { // ListGrantsRequest
  Limit: Number("int"),
  Marker: "STRING_VALUE",
  KeyId: "STRING_VALUE", // required
  GrantId: "STRING_VALUE",
  GranteePrincipal: "STRING_VALUE",
};
const command = new ListGrantsCommand(input);
const response = await client.send(command);
// { // ListGrantsResponse
//   Grants: [ // GrantList
//     { // GrantListEntry
//       KeyId: "STRING_VALUE",
//       GrantId: "STRING_VALUE",
//       Name: "STRING_VALUE",
//       CreationDate: new Date("TIMESTAMP"),
//       GranteePrincipal: "STRING_VALUE",
//       RetiringPrincipal: "STRING_VALUE",
//       IssuingAccount: "STRING_VALUE",
//       Operations: [ // GrantOperationList
//         "Decrypt" || "Encrypt" || "GenerateDataKey" || "GenerateDataKeyWithoutPlaintext" || "ReEncryptFrom" || "ReEncryptTo" || "Sign" || "Verify" || "GetPublicKey" || "CreateGrant" || "RetireGrant" || "DescribeKey" || "GenerateDataKeyPair" || "GenerateDataKeyPairWithoutPlaintext" || "GenerateMac" || "VerifyMac" || "DeriveSharedSecret",
//       ],
//       Constraints: { // GrantConstraints
//         EncryptionContextSubset: { // EncryptionContextType
//           "<keys>": "STRING_VALUE",
//         },
//         EncryptionContextEquals: {
//           "<keys>": "STRING_VALUE",
//         },
//       },
//     },
//   ],
//   NextMarker: "STRING_VALUE",
//   Truncated: true || false,
// };

ListGrantsCommand Input

See ListGrantsCommandInput for more details

Parameter
Type
Description
KeyId
Required
string | undefined

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.

GrantId
string | undefined

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

GranteePrincipal
string | undefined

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

Limit
number | undefined

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
string | undefined

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.

ListGrantsCommand Output

See ListGrantsCommandOutput for details

Parameter
Type
Description
$metadata
Required
ResponseMetadata
Metadata pertaining to this request.
Grants
GrantListEntry[] | undefined

A list of grants.

NextMarker
string | undefined

When Truncated is true, this element is present and contains the value to use for the Marker parameter in a subsequent request.

Truncated
boolean | undefined

A flag that indicates whether there are more items in the list. When this value is true, the list in this response is truncated. To get more items, pass the value of the NextMarker element in this response to the Marker parameter in a subsequent request.

Throws

Name
Fault
Details
DependencyTimeoutException
server

The system timed out while trying to fulfill the request. You can retry the request.

InvalidArnException
client

The request was rejected because a specified ARN, or an ARN in a key policy, is not valid.

InvalidGrantIdException
client

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

InvalidMarkerException
client

The request was rejected because the marker that specifies where pagination should next begin is not valid.

KMSInternalException
server

The request was rejected because an internal exception occurred. The request can be retried.

KMSInvalidStateException
client

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
client

The request was rejected because the specified entity or resource could not be found.

KMSServiceException
Base exception class for all service exceptions from KMS service.