Jump to Content

New API Documentation - Developer Preview Available

We are excited to announce the developer preview of our new API documentation for AWS SDK for JavaScript v3. Please follow instructions on the landing page to leave us your feedback.

Class ListGrantsCommandProtected

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:

Example

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",
// ],
// Constraints: { // GrantConstraints
// EncryptionContextSubset: { // EncryptionContextType
// "<keys>": "STRING_VALUE",
// },
// EncryptionContextEquals: {
// "<keys>": "STRING_VALUE",
// },
// },
// },
// ],
// NextMarker: "STRING_VALUE",
// Truncated: true || false,
// };

Param

ListGrantsCommandInput

Returns

ListGrantsCommandOutput

See

Throws

DependencyTimeoutException (server fault)

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

Throws

InvalidArnException (client fault)

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

Throws

InvalidGrantIdException (client fault)

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

Throws

InvalidMarkerException (client fault)

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

Throws

KMSInternalException (server fault)

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

Throws

KMSInvalidStateException (client fault)

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.

Throws

NotFoundException (client fault)

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

Throws

KMSServiceException

Base exception class for all service exceptions from KMS service.

Example

To list grants for a KMS key

// The following example lists grants for the specified KMS key.
const input = {
"KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab"
};
const command = new ListGrantsCommand(input);
const response = await client.send(command);
/* response ==
{
"Grants": [
{
"CreationDate": "2016-10-25T14:37:41-07:00",
"GrantId": "91ad875e49b04a9d1f3bdeb84d821f9db6ea95e1098813f6d47f0c65fbe2a172",
"GranteePrincipal": "acm.us-east-2.amazonaws.com",
"IssuingAccount": "arn:aws:iam::111122223333:root",
"KeyId": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"Operations": [
"Encrypt",
"ReEncryptFrom",
"ReEncryptTo"
],
"RetiringPrincipal": "acm.us-east-2.amazonaws.com"
},
{
"CreationDate": "2016-10-25T14:37:41-07:00",
"GrantId": "a5d67d3e207a8fc1f4928749ee3e52eb0440493a8b9cf05bbfad91655b056200",
"GranteePrincipal": "acm.us-east-2.amazonaws.com",
"IssuingAccount": "arn:aws:iam::111122223333:root",
"KeyId": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"Operations": [
"ReEncryptFrom",
"ReEncryptTo"
],
"RetiringPrincipal": "acm.us-east-2.amazonaws.com"
},
{
"CreationDate": "2016-10-25T14:37:41-07:00",
"GrantId": "c541aaf05d90cb78846a73b346fc43e65be28b7163129488c738e0c9e0628f4f",
"GranteePrincipal": "acm.us-east-2.amazonaws.com",
"IssuingAccount": "arn:aws:iam::111122223333:root",
"KeyId": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"Operations": [
"Encrypt",
"ReEncryptFrom",
"ReEncryptTo"
],
"RetiringPrincipal": "acm.us-east-2.amazonaws.com"
},
{
"CreationDate": "2016-10-25T14:37:41-07:00",
"GrantId": "dd2052c67b4c76ee45caf1dc6a1e2d24e8dc744a51b36ae2f067dc540ce0105c",
"GranteePrincipal": "acm.us-east-2.amazonaws.com",
"IssuingAccount": "arn:aws:iam::111122223333:root",
"KeyId": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab",
"Operations": [
"Encrypt",
"ReEncryptFrom",
"ReEncryptTo"
],
"RetiringPrincipal": "acm.us-east-2.amazonaws.com"
}
],
"Truncated": true
}
*/
// example id: to-list-grants-for-a-cmk-1481067365389

Hierarchy

Constructors

Properties

middlewareStack: MiddlewareStack<ListGrantsCommandInput, ListGrantsCommandOutput>

Methods