Skip to main content

GetKeyPolicy

Gets a key policy attached to the specified KMS key.

Description

The `GetKeyPolicy` operation retrieves a key policy attached to a KMS key. By default, this operation returns the default key policy.

note
  • The KMS key that you use for this operation must be in a compatible key state.
  • The policy document returned by this operation is the actual policy that is in effect, not a template or default policy.
  • If you specify a policy name other than the default policy, the operation fails unless that policy exists.

Request Syntax

Headers

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

Request Body

NameDescriptionRequiredType
KeyIdThe identifier of the KMS key whose key policy you want to retrieve. This can be the key ID or key ARN of the KMS key.Yesstring
PolicyNameSpecifies the name of the key policy to retrieve. Currently, the only valid name is "default".Yesstring
POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.GetKeyPolicy
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "PolicyName": "default" }
Values in italics indicate user input and should be replaced with actual values.

Examples

Example 1: Get the default key policy for a KMS key

POST / HTTP/1.1
Content-Type: application/x-amz-json-1.1
X-Amz-Target: TrentService.GetKeyPolicy
{ "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "PolicyName": "default" }
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
{ "Policy": "{\"Version\":\"2012-10-17\",\"Id\":\"key-default-1\",\"Statement\":[{\"Sid\":\"Enable IAM User Permissions\",\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"arn:aws:iam::111122223333:root\"},\"Action\":\"kms:*\",\"Resource\":\"*\"}]}" }
Values in italics indicate variable response values.

Response Elements

NameDescriptionRequiredType
PolicyA key policy document in JSON format.NoString

Special Errors

Error CodeDescription
DependencyTimeoutExceptionThe system timed out while trying to fulfill the request.
InvalidArnExceptionThe request was rejected because a specified ARN was not valid.
KMSInternalExceptionAn internal error occurred.
KMSInvalidStateExceptionThe request was rejected because the key state is not valid for this operation.
NotFoundExceptionThe request was rejected because the specified entity or resource could not be found.

Permissions

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

  • `kms:GetKeyPolicy` on the KMS key (specified in the policy)

Try It Out

Test GetKeyPolicy

Get a key policy for a KMS key.

Coming Soon

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