Skip to main content

CreateGrant

Creates a grant for a KMS key. A grant is a policy instrument that allows AWS principals to use KMS keys in cryptographic operations.

Description

A grant gives AWS principals long-term permissions to use KMS keys in cryptographic operations. You can create a grant to allow a principal to use the KMS key in specified operations. You can also use a grant to allow the principal to delegate their grant permissions to other principals.

Request Syntax

Headers

NameDescriptionRequiredType
Content-TypeMust be "application/x-amz-json-1.1"Yesstring
X-Amz-TargetMust be "TrentService.CreateGrant"Yesstring

Request Body

NameDescriptionRequiredType
KeyIdThe unique identifier for the KMS key that the grant applies to.Yestext
GranteePrincipalThe principal that is given permission to perform the operations that the grant permits.Yestext
OperationsA list of operations that the grant permits (as JSON array).Yestext
RetiringPrincipalThe principal that is given permission to retire the grant by using RetireGrant operation.Notext
ConstraintsA structure that you can use to allow the operations permitted by the grant only when the grant request includes particular encryption context keys or values (as JSON object).Notext
NameA friendly name for identifying the grant. Use the same name to refer to the same grant in subsequent requests.Notext
POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.CreateGrant
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "GranteePrincipal": "arn:aws:iam::111122223333:role/ExampleRole", "Operations": [ "Decrypt", "Encrypt" ], "Name": "ExampleGrant" }
Values in italics indicate user input and should be replaced with actual values.

Response Elements

NameDescriptionRequiredType
GrantIdThe unique identifier for the grant.NoString
GrantTokenThe grant token. Use this value to establish the scope of the grant during its early phase, before the grant is replicated to all Q-KMS hosts.NoString

Examples

Example 1: Create a grant for encryption and decryption

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.CreateGrant
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "GranteePrincipal": "arn:aws:iam::111122223333:role/ExampleRole", "Operations": [ "Decrypt", "Encrypt" ], "Name": "ExampleGrant" }
Values in italics indicate user input and should be replaced with actual values.
HTTP/1.1 200 OK
Content-Type: application/x-amz-json-1.1
{ "GrantId": "0c237476b39f8bc44e45212e08498fbe3151305030726c0590dd8d3e9f3d6a60", "GrantToken": "AQpAM2RhZTk1MGMyNTk2ZmCjsrRInph6PxKRieR4..." }
Values in italics indicate variable response values.

Example 2: Create a grant with encryption context constraints

Special Errors

Error CodeDescription
DependencyTimeoutExceptionThe system timed out while trying to fulfill the request.
DisabledExceptionThe request was rejected because the specified KMS key is disabled.
InvalidArnExceptionThe request was rejected because a specified ARN was not valid.
InvalidGrantTokenExceptionThe request was rejected because the specified grant token is not valid.
KeyUnavailableExceptionThe request was rejected because the specified KMS key was not available.
KMSInternalExceptionThe request was rejected because an internal error occurred.
KMSInvalidStateExceptionThe request was rejected because the state of the specified resource is not valid for this request.
LimitExceededExceptionThe request was rejected because a quota was exceeded.
NotFoundExceptionThe request was rejected because the specified entity or resource could not be found.

Permissions

To use the `CreateGrant` operation, you must have the following permissions:

  • `kms:CreateGrant` on the KMS key

Try It Out

Test CreateGrant

Create a grant for a KMS key to allow specific cryptographic operations.

Coming Soon

This feature is currently under development and will be available soon.