Attaches a key policy to the specified KMS key. You can use this operation to set only the
default key policy.
For more information about key policies, see
Key Policies in the
Key Management Service Developer Guide. For help writing and formatting a JSON policy document, see the
IAM JSON Policy Reference in the
Identity and Access Management User Guide. For examples of adding a key policy in multiple programming languages, see
Use PutKeyPolicy with an Amazon Web Services SDK or CLI in the
Key Management Service Developer Guide.
A KMS key can also have an
AWS_RAM key policy, which Resource Access Manager (RAM) manages for KMS keys that you share through RAM. You can't use
PutKeyPolicy to create, change, or delete the
AWS_RAM key policy. If you set
PolicyName to
AWS_RAM, the request fails with a
ValidationException and the message
The AWS_RAM policy can only be managed by the RAM service. To view the
AWS_RAM key policy, use
GetKeyPolicy. For information about sharing KMS keys, see
Sharing KMS keys with RAM in the
Key Management Service Developer Guide.
Cross-account use: No. You cannot perform this operation on a KMS key in a different Amazon Web Services account.
Required permissions:
kms:PutKeyPolicy (key policy)
You can use the
kms:PolicyName condition key to control access to this operation based on the value of the
PolicyName parameter in the request. If the request doesn't include
PolicyName, the value of
kms:PolicyName is
default.
Related operations:
GetKeyPolicyEventual consistency: The KMS API follows an eventual consistency model. For more information, see
KMS eventual consistency.