AWS CloudFormation
User Guide (Version )

AWS::KMS::Key

The AWS::KMS::Key resource specifies a customer master key (CMK) in AWS Key Management Service (AWS KMS). Authorized users can use the CMK to encrypt and decrypt small amounts of data (up to 4096 bytes), but they are more commonly used to generate data keys. You can also use CMKs to encrypt data stored in AWS services that are integrated with AWS KMS or within their applications. For more information, see What is the AWS Key Management Service? in the AWS Key Management Service Developer Guide.

Syntax

To declare this entity in your AWS CloudFormation template, use the following syntax:

JSON

{ "Type" : "AWS::KMS::Key", "Properties" : { "Description" : String, "Enabled" : Boolean, "EnableKeyRotation" : Boolean, "KeyPolicy" : Json, "KeyUsage" : String, "PendingWindowInDays" : Integer, "Tags" : [ Tag, ... ] } }

YAML

Type: AWS::KMS::Key Properties: Description: String Enabled: Boolean EnableKeyRotation: Boolean KeyPolicy: Json KeyUsage: String PendingWindowInDays: Integer Tags: - Tag

Properties

Description

A description of the CMK. Use a description that helps you to distinguish this CMK from others in the account, such as its intended use.

Required: No

Type: String

Minimum: 0

Maximum: 8192

Update requires: No interruption

Enabled

Specifies whether the customer master key (CMK) is enabled. Disabled CMKs cannot be used in cryptographic operations.

When Enabled is true, the key state of the CMK is Enabled. When Enabled is false, the key state of the CMK is Disabled. The default value is true.

The actual key state of the CMK might be affected by actions taken outside of CloudFormation, such as running the EnableKey, DisableKey, or ScheduleKeyDeletion operations.

For information about the key states of a CMK, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide.

Required: No

Type: Boolean

Update requires: No interruption

EnableKeyRotation

Enables automatic rotation of the key material for the specified customer master key (CMK). By default, automation key rotation is not enabled.

When you enable automatic rotation, AWS KMS automatically creates new key material for the CMK 365 days after the enable (or reenable) date and every 365 days thereafter. AWS KMS retains all key material until you delete the CMK.

For detailed information about automatic key rotation, see Rotating Customer Master Keys in the AWS Key Management Service Developer Guide.

Required: No

Type: Boolean

Update requires: No interruption

KeyPolicy

The key policy that authorizes use of the CMK. The key policy must observe the following rules.

  • The key policy must allow the caller to make a subsequent PutKeyPolicy request on the CMK. This reduces the risk that the CMK becomes unmanageable. For more information, refer to the scenario in the Default Key Policy section of the AWS Key Management Service Developer Guide .

  • Each statement in the key policy must contain one or more principals. The principals in the key policy must exist and be visible to AWS KMS. When you create a new AWS principal (for example, an IAM user or role), you might need to enforce a delay before including the new principal in a key policy because the new principal might not be immediately visible to AWS KMS. For more information, see Changes that I make are not always immediately visible in the AWS Identity and Access Management User Guide.

  • The key policy size limit is 32 kilobytes (32768 bytes).

If you are unsure of which policy to use, consider the default key policy. This is the key policy that AWS KMS applies to CMKs that are created by using the CreateKey API with no specified key policy. It gives the AWS account that owns the key permission to perform all operations on the key. It also allows you write IAM policies to authorize access to the key. For details, see Default Key Policy in the AWS Key Management Service Developer Guide.

Required: Yes

Type: Json

Minimum: 1

Maximum: 131072

Pattern: [\u0009\u000A\u000D\u0020-\u00FF]+

Update requires: No interruption

KeyUsage

Determines the cryptographic operations for which you can use the CMK. The default value is ENCRYPT_DECRYPT. This parameter is required only for asymmetric CMKs. You can't change the KeyUsage value after the CMK is created.

Select only one valid value.

  • For symmetric CMKs, omit the parameter or specify ENCRYPT_DECRYPT.

  • For asymmetric CMKs with RSA key material, specify ENCRYPT_DECRYPT or SIGN_VERIFY.

  • For asymmetric CMKs with ECC key material, specify SIGN_VERIFY.

Required: No

Type: String

Allowed Values: ENCRYPT_DECRYPT | SIGN_VERIFY

Update requires: Replacement

PendingWindowInDays

Specifies the number of days in the waiting period before AWS KMS deletes a CMK that has been removed from a CloudFormation stack. Enter a value between 7 and 30 days. The default value is 30 days.

When you remove a customer master key (CMK) from a CloudFormation stack, AWS KMS schedules the CMK for deletion and starts the mandatory waiting period. The PendingWindowInDays property determines the length of waiting period. During the waiting period, the key state of CMK is Pending Deletion, which prevents the CMK from being used in cryptographic operations. When the waiting period expires, AWS KMS permanently deletes the CMK.

You cannot use a CloudFormation template to cancel deletion of the CMK after you remove it from the stack, regardless of the waiting period. If you specify a CMK in your template, even one with the same name, CloudFormation creates a new CMK. To cancel deletion of a CMK, use the AWS KMS console or the CancelKeyDeletion operation.

For information about the PendingDeletion key state, see How Key State Affects Use of a Customer Master Key in the AWS Key Management Service Developer Guide. For more information about deleting CMKs, see the ScheduleKeyDeletion operation in the AWS Key Management Service API Reference and Deleting Customer Master Keys in the AWS Key Management Service Developer Guide.

Minimum: 7

Maximum: 30

Required: No

Type: Integer

Update requires: No interruption

Tags

An array of key-value pairs to apply to this resource.

For more information, see Tag.

Required: No

Type: List of Tag

Update requires: No interruption

Return Values

Ref

When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the key ID, such as 1234abcd-12ab-34cd-56ef-1234567890ab.

For more information about using the Ref function, see Ref.

Fn::GetAtt

The Fn::GetAtt intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.

For more information about using the Fn::GetAtt intrinsic function, see Fn::GetAtt.

Arn

The Amazon Resource Name (ARN) of the AWS KMS customer master key (CMK), such as arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab.

For help with finding the ARN of a CMK, see Finding the Key ID and ARN in the AWS Key Management Service Developer Guide.

Examples

Create a customer master key

The following example creates a customer managed CMK. The key policy for the CMK allows Alice to manage the key and allows Bob to view the CMK and use it in cryptographic operations. It also allows the AWS account (root) full access to the key. This prevents you from losing control of the key if both Alice and Bob are deleted from the account.

JSON

"myKey" : { "Type" : "AWS::KMS::Key", "Properties" : { "Description" : "An example CMK", "KeyPolicy" : { "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": "*" }, { "Sid": "Allow administration of the key", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:user/Alice" }, "Action": [ "kms:Create*", "kms:Describe*", "kms:Enable*", "kms:List*", "kms:Put*", "kms:Update*", "kms:Revoke*", "kms:Disable*", "kms:Get*", "kms:Delete*", "kms:ScheduleKeyDeletion", "kms:CancelKeyDeletion" ], "Resource": "*" }, { "Sid": "Allow use of the key", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:user/Bob" }, "Action": [ "kms:DescribeKey", "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey", "kms:GenerateDataKeyWithoutPlaintext" ], "Resource": "*" } ] } } }

YAML

myKey: Type: AWS::KMS::Key Properties: Description: "An example CMK" KeyPolicy: 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: "*" - Sid: "Allow administration of the key" Effect: "Allow" Principal: - AWS: "arn:aws:iam::123456789012:user/Alice" Action: - "kms:Create*" - "kms:Describe*" - "kms:Enable*" - "kms:List*" - "kms:Put*" - "kms:Update*" - "kms:Revoke*" - "kms:Disable*" - "kms:Get*" - "kms:Delete*" - "kms:ScheduleKeyDeletion" - "kms:CancelKeyDeletion" Resource: "*" - Sid: "Allow use of the key" Effect: "Allow" Principal: - AWS: "arn:aws:iam::123456789012:user/Bob" Action: - "kms:DescribeKey" - "kms:Encrypt" - "kms:Decrypt" - "kms:ReEncrypt*" - "kms:GenerateDataKey" - "kms:GenerateDataKeyWithoutPlaintext" Resource: "*"

Create a CMK with a tag

The following example creates a custom CMK with a single tag.

JSON

{ "Resources" : { "myKey" : { "Type" : "AWS::KMS::Key", "Properties" : { "KeyPolicy" : { "Version": "2012-10-17", "Id": "key-default-1", "Statement": [ { "Sid": "Enable IAM User Permissions", "Effect": "Allow", "Principal": { "AWS": { "Fn::Join" : ["" , ["arn:aws:iam::", {"Ref" : "AWS::AccountId"} ,":root" ]] } }, "Action": "kms:*", "Resource": "*" } ] }, "Tags" : [ { "Key" : {"Ref" : "Key"}, "Value" : {"Ref" : "Value"} } ] } } }, "Parameters" : { "Key" : { "Type" : "String" }, "Value" : { "Type" : "String" } } }

YAML

Resources: myKey: Type: AWS::KMS::Key Properties: KeyPolicy: Version: 2012-10-17 Id: key-default-1 Statement: - Sid: Enable IAM User Permissions Effect: Allow Principal: AWS: !Join - '' - - 'arn:aws:iam::' - !Ref 'AWS::AccountId' - ':root' Action: 'kms:*' Resource: '*' Tags: - Key: !Ref Key Value: !Ref Value Parameters: Key: Type: String Value: Type: String

See Also