- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
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
Parameter | Type | Description |
---|
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:
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 |
ListGrantsCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
Grants | GrantListEntry[] | undefined | A list of grants. |
NextMarker | string | undefined | When |
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 |
Throws
Name | Fault | Details |
---|
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 |
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:
|
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. |